Here is a piece of code that I've written to get the last lines in a file for one of my programs:
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);
}
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 ;)