in reply to Re^3: reading a line from file two times
in thread reading a line from file two times
There's definitely someting screwy with using a negative, relative seek (on Win32). To back up over a line consisting of 8 chars + NL, requires seeking back -6.
I'd expect to have to seek back more than the line length, not less to account for the newline?
#! perl -slw use strict; while( <DATA> ) { chomp; print; if( /the line/ ) { my $backup = -length() + 2; print "Backing up $backup places"; seek DATA, $backup, 1; chomp( $_ = <DATA> ); print "?$_?"; } } =output c:\test>junk junk junk more junk the line Backing up -6 places ?the line? other junk yet more junk =cut __DATA__ junk junk more junk the line other junk yet more junk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: reading a line from file two times
by jettero (Monsignor) on Dec 21, 2006 at 05:36 UTC |