in reply to Dealing with nextline of a file

Hi jnarayan81,

you can adapt the following code, seen on the web as "Rolling buffer" (by Toby Inkster or Ingy döt Net, can't remember):
For $n=2, on each iteration, $cache[0] and $cache[1] will contain a pair of adjacent lines.
#!/usr/bin/perl ## Go through a stream and prints all but the last n lines where n is +a command line argument: my @cache; my $n = shift @ARGV; while(<>) { push @cache, $_; print shift @cache if @cache > $n; }