This is harder than printing the first lines! Here are a few options: from smallest to smartest:
Just use tail
Because who really needs a perl script to print the last two lines of a file?
Read all the lines from the file in the list and print the last two.
print do {
open my $info, $file or die ...;
(<$info>)[-2, -1];
};
Read all the lines from the file, just remembering the last two.
open my $info, $file or die ...;
my @lines;
while (my $line = <$info>) {
shift @lines if @lines == 2;
push @lines, $line;
}
print @lines;
, ; , .
, "" , . : File::ReadBackwards. :
use File::ReadBackwards;
my $info = File::ReadBackwards->new($file) or die ...;
my $last = $info->readline;
my $second_last = $info->readline;
print $second_last, $last;