in reply to Re^2: Unexpected result using tell/seek within the __DATA__ file
in thread Unexpected result using tell/seek within the __DATA__ file

Perl reads the source code using readline and not using binmode. This means that tell needs to guess at what the difference is between where perl stopped reading stuff into the buffer and where your script stopped reading stuff out of the buffer.

So perl gets the accurate seek position of the end of the buffered data and then subtracts the number of bytes in the buffer. For every "\n" in the buffer, there were two bytes ("\r\n") in the file so the tell result is "off" by that many bytes.

- tye        

  • Comment on Re^3: Unexpected result using tell/seek within the __DATA__ file (buffer)

Replies are listed 'Best First'.
Re^4: Unexpected result using tell/seek within the __DATA__ file (buffer)
by Gulliver (Monk) on Mar 11, 2011 at 19:49 UTC

    I have used tell/seek lots of times to get back to the beginning of DATA and have never had a problem. This is the first time I have seen this and it only seems to be off when I seek within the DATA section. Then it is off by 1 per newline.

    If what you are saying is true, shouldn't it be off regardless of the start of DATA?

Re^4: Unexpected result using tell/seek within the __DATA__ file (buffer)
by Gulliver (Monk) on Mar 11, 2011 at 22:11 UTC

    Thanks! I understand now what you mean. The first "tell DATA" is just giving the value left there by Perl which is correct. Subsequent calls to "tell DATA" are calculated and are off in Windows. I'll check tonight that this works on Linux.