in reply to Out of memory problem when copying contents of file into array

Below, I use an array to keep tract of the last 100 lines read from the file. This keeps you from having to read the entire file into memory, giving you an out of memory error.

sub tailFile { my ($file, $lines) = @_; open F, $file or die $!; my @lines; while (<F>) { push @lines, $_; shift @lines if @lines > $lines; } close F; return @lines }

Update: As suggested, you may want to check out File::ReadBackwards. After all, you should always re-use a well developed and test module over re-inventing the wheel. But, atleast my code give you one way of doing it.

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)