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

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

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
    Should be on systems where seek($fh, $amount, SEEK_CUR) works correctly, you'd have to backup over all the characters read. So if the length($entire_string) is 10 (including LF or CRLF), that'd be: seek($fh, -10, SEEK_CUR). I do seem to recall that it behaves unexpectedly (for a unix nerd) in windows, but my experience was in foxpro, not perl — that definitely shouldn't count.

    -Paul