Reads a file in reverse until the date is nolonger today. Useful for looking for errors in a log file that uses date stamps like Sun Aug 12 08:00:00 2001. I am using it for looking for oracle errors in my alert log.
my $file; my @lines; open FH, 'yourlogfile.log'; @lines = <FH>; LINE: while ($file = pop @lines) { if ( $file =~ m/^ORA*/ ) { print "$file\n"; } last LINE if ($file !~ m/^$today*/ && $file =~ m/^(\S+\s+\S+\s+\d+)\s+\d+:\d+:\d+\s+(\d+)/x ); }

Replies are listed 'Best First'.
Re: Reading a file in reverse until yesterdays date.
by runrig (Abbot) on Aug 14, 2001 at 01:29 UTC
    If the log file is large (which log files sometimes tend to be) then you might want to use File::ReadBackwards or risk getting an 'Out of memory' error.
Re: Reading a file in reverse until yesterdays date.
by Anonymous Monk on Aug 14, 2001 at 01:24 UTC
    Replace the line if ( $file =~ m/^ORA*/ ) with the error that you are looking for. if ( $file =~ m/^ERR*/ )