in reply to tail a file in perl
I think this code is simple enough to understand what is going on, but if you need to explain more I will. (I have to get some real work done first ;)my @lines; my $currLine = 0; my $maxLines = 10; # Go through the file, saving the last $maxLines while (<>){ $lines[$currLine] = $_; $currLine++; $currLine = 0 if ($currLine == $maxLines); } # Print out the last $maxLines for (1..$maxLines){ print $lines[$currLine]; $currLine++; $currLine = 0 if ($currLine == $maxLines); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: tail a file in perl
by blokhead (Monsignor) on Oct 23, 2002 at 17:22 UTC |