Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl script question

Reply
Thread Tools

Perl script question

 
 
George Monappallil
Guest
Posts: n/a
 
      02-15-2005
Hi Guys:
Below is my code.
How can I grab the last data of the first column of the output of egrep -n
and store it in a file for comparing it against the last data next time the
script is run.
Is there an easier way of doing this?
Your help is appreciated.

------------------------------
#!/bin/perl

$LOG = "./messages.log";

$SIG{"INT"} = "clean_exit";
$SIG{"TERM"} = "clean_exit";

open(FILE, $LOG) || die "Can not open file $LOG";

# Main loop.
$WORD = "ERROR";
if ($LOG) {
$CURRLINECNT=`egrep -n $WORD $LOG | awk -F":" '{print $1}'`;
# THIS DOES NOT WORK EITHER. What's wrong in the syntax ?
}

# We jump here in case of INT or TERM signals
sub clean_exit {
($signal) = @_;
close FILE;
print "$file closed.\nExiting on signal $signal...\n";
exit;
}
--------------------------


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-15-2005
George Monappallil wrote:
> Hi Guys:
> Below is my code.
> How can I grab the last data of the first column of the output of
> egrep -n and store it in a file for comparing it against the last
> data next time the script is run.
> Is there an easier way of doing this?
> Your help is appreciated.
>
> ------------------------------
> #!/bin/perl


You are missing

use warnings;
use strict;

> $LOG = "./messages.log";
>
> $SIG{"INT"} = "clean_exit";
> $SIG{"TERM"} = "clean_exit";


Useless use of double quotes. In this particular case they don't cause any
harm, but that's not always the case.
There is a FAQ about the topic.

> open(FILE, $LOG) || die "Can not open file $LOG";


You may want to add the reason _why_ the open failed, see variable $!.

> # Main loop.


But there is no loop anywhere here

> $WORD = "ERROR";
> if ($LOG) {
> $CURRLINECNT=`egrep -n $WORD $LOG | awk -F":" '{print
> $1}'`; # THIS DOES NOT WORK EITHER. What's wrong in the syntax ?


Gaaaaaack! Why do you fork an external process instead of using Perl's
buildin functions?
Also, if you would have used warnings and strictures, then perl would have
told you quite a few things about this line like e.g that $1 is undefined
because you never had a successful pattern match in your program.

jue



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI: Execute a perl script inside another perl script xdarcos@hotmail.com Perl Misc 20 01-18-2005 12:33 PM
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM



Advertisments