in reply to Skip and Scan Lines
Second, if you restructure the logic a little bit, you can do it all with just one while loop -- something like this:
(update: fixed the second condition (from "unless" to "if") to match the OP's intent. Actually, fixed two other typos in that same line as well -- not having a way to test my work makes me less reliable!)my $ref_time = time(); my $ref_delta = $serverRef->{ScanErrlogLastDays}*24*3600; while (<LOG>) { next unless ( /^\s*([\d\/\-]+\s+[\d\.\:]+)\s+/ ); next if ( $ref_time - str2time( $1 ) > $ref_delta ); $ref->{start_check_datetime} = $1; # put all the stuff from the second while loop here } # all done, and you didn't miss the first record
another update: Since consecutive lines in the input log file are guaranteed to be in chronological order, it's probably worthwhile to avoid doing the time arithmetic over and over, once you hit the first sought-for record -- I realize that this must have been (part of) the reasoning behind having two while loops in your approach. I also realize that my initial suggestion would keep assigning new values to ref->{start_check_datetime} -- which is probably a mistake. You could fix this as follows:
my $seeking = 1; my $ref_time = time(); my $ref_delta = $serverRef->{ScanErrlogLastDays}*24*3600; while (<LOG>) { if ( $seeking ) { next unless ( /^\s*([\d\/\-]+\s+[\d\.\:]+)\s+/ ); next if ( $ref_time - str2time( $1 ) > $ref_delta ); $ref->{start_check_datetime} = $1; $seeking = 0; } # put all the stuff from the second while loop here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Skip and Scan Lines
by Anonymous Monk on Mar 22, 2004 at 18:58 UTC |