in reply to optimize the code
Untested, but I think this should run substantially more quickly.
The basic idea is instead of converting all 11 million GMT dates to match your PST target date, you convert the target date to GMT and use a simple regex to do the matching:
my $target = UnixDate( Date_ConvTZ( ParseDate("3 days ago"), 'PST', 'GMT' ) ,"%e/%h/%Y" ); open DATA,">$ARGV[1]"; open FH,"$ARGV[0]"; m/\[$target:/ and print DATA $_ while <FH>; close DATA; close FH;
If there might be other dates embedded in the log that would be matched by the regex [...:, then you might need to elaborate the regex to isolate the required date.
Alternatively, if as your sample suggests the required date is at a set offset from the start of the line, you might use:
substr( $_, 34, 11 ) eq $target and print DATA $_ while <FH>
which as a straight string compare would be even quicker.
This assumes that your "3 days earlier" runs midnight to midnight GMT on that day. If you need to cater for the timezone shift of the start and end of day, then things get more complicated. But your code doesn't appear to be doing that.
In that case I probably calculate the unixtime (seconds since epoch) of the start and end times, convert the log date/times to the same and use a numeric compare:
print if $logSecs > $startSecs && $logSecs < $endSecs;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: optimize the code
by Anonymous Monk on Jun 25, 2010 at 05:18 UTC | |
by Anonymous Monk on Jun 29, 2010 at 07:28 UTC | |
by marto (Cardinal) on Jun 29, 2010 at 08:22 UTC |