in reply to Read File in reverse
I kind of like the tied filehandle method with that module:
use File::ReadBackwards; tie *BW, 'File::ReadBackwards', 'log_file' or die "can't read 'log_file' $!" ; while( <BW> ) { print ; }
You could also use Tie::File and just loop over indices of -1, -2, -3, -4, etc.
Update: Here's an example of the Tie::File method.
use Tie::File; tie my @array, 'Tie::File', 'log_file' or die "can't read 'log_file' $!"; for ( 1 .. @array ) { $_ = -$_; print $array[$_]; }
Note that when counting indeces from the end going backward with an array, the last element starts at -1, not 0, and the first element will be -@array, not -$#array. Just a possible gotcha to watch out for.
Dave
|
|---|