you need to explicitly save the lines you'll want. you'll probably not need to save more than a few, so this is not really a big deal. define a list, and keep them as you go:
sub process { print 'foo'; }
my @oldlines = ();
my $LINES_TO_KEEP = 10;
while(<>) {
# drop the entry on the bottom, and add $_ to the top
unshift @oldlines;
scalar(@oldlines)>$LINES_TO_KEEP && pop @oldlines;
# do your processing here. call process first unless you
# want @oldlines to hold the unmodified version of the
# line
process($_);
}
In reply to Re: read lines... wait
by dlc
in thread read lines... wait, back up?
by Konda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |