in reply to Re: Problem using File::ReadBackwards
in thread Problem using File::ReadBackwards

You all were right.

It turned out the log file had empty lines in it, for whatever reason our developers decided to stick them in there.

I easily solved it by simply doing:

next if $log_line =~ /^$/;
prior to
last if $log_line lt $earliest;

Replies are listed 'Best First'.
Re^3: Problem using File::ReadBackwards
by rpanman (Scribe) on Jul 10, 2007 at 18:41 UTC
    ysth is dead right. Why check for the one case which you know doesn't work and exclude it? It would be safer (in case your designers do something else weird) to look for the condition that satisfies your requirements.

    I'll even save you the typing:
    while ( defined( my $log_line = $bw->readline() ) ) { my ($logTime) = ($log_line =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{ +2}).*ProcessHTTPRequestImpl/); if ($logTime){ last if $logTime lt $earliest; print $log_line; } }
    Please don't use:
    next if $log_line =~ /^$/;
    ... I shudder just thinking about it :-)
Re^3: Problem using File::ReadBackwards
by ysth (Canon) on Jul 10, 2007 at 17:51 UTC