in reply to Print all lines in a file except the last two

This works for me...
$lines = `/usr/bin/wc -l afile.txt`; open(F, '<afile.txt') || die 'cannot open afile.txt'; $cntr = 0; while (<F>) { $cntr++; print; last if $cntr == $lines - 2; }
on my unix box.

Replies are listed 'Best First'.
Re: Re: Print all lines in a file except the last two
by revdiablo (Prior) on May 20, 2004 at 19:16 UTC

    There is a magic variable that keeps track of the current line number from the last-read filehandle. This would make your while loop a bit simpler:

    $. < $lines - 2 and print while <F>