You could try a binary search with seek() to look for the general area to start looking. Something like:
# Find a good place to start traversing a large # file for sorted data. return 0 if $filelen < 2000000; # A few MB? Please... :-) my $safe_offset = 0; my $jump = 0.5; my $step = 0.25; for(1..8) { # See if my($testoff) = int($filelen * $jump); seek(FILE, $testoff, 0); if ( do_test(*FILE, $threshold) ) { $safe_offset = $testoff; # Point to offset for $jump = $jump + $step; } else { $jump = $jump - $step; } $step = $step / 2.0; } # Go to selected place: seek(FILE, $safe_offset); <FILE> if $safe_offset > 0; return $safe_offset; sub do_test { my(*FILE, $compare) = @_; # Has moved somewhere in file. Skip partial line of log: <FILE>; my $log = <FILE>; # You write this (you know the format). Return true if OK: return date_test($log, $compare); }
Just an idea, ignore if my assumption about your problem was wrong. Code is untested since I'm busy. I'll be back in about a work day and can write more then, if you need more details.
I hope this won't embarrass me when I get back. (-: On the other hand -- I'll make someone's day when they get to point out errors. :-)
Update: Added return stuff, so it sets up offset to file correctly.
In reply to Re: print log file
by BerntB
in thread print log file
by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |