in reply to Re: going back to a specific line for reading.
in thread going back to a specific line for reading.

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: going back to a specific line for reading.

Replies are listed 'Best First'.
Re^3: going back to a specific line for reading.
by Joost (Canon) on Jun 13, 2007 at 15:02 UTC
Re^3: going back to a specific line for reading.
by ysth (Canon) on Jun 13, 2007 at 19:44 UTC
    Then always save the positions for the last three lines, something like:
    #!/usr/bin/perl use warnings; use strict; my @positions; my $read_through = 0; while (push(@positions,tell(STDIN)), defined(my $line = <STDIN>)) { print "got line: $line"; # if the line contains a $ and this is the first time we've # got this far in the file, jump back 3 if (index($line, '$') >= 0 && $read_through < $positions[-1]) { $read_through = $positions[-1]; seek(STDIN, $positions[-4] || 0, 0) or die "whoops, couldn't see +k: $!"; } # do stuff with $line # only keep positions for last three lines splice(@positions, 0, -3, ()); }