in reply to Back Navigation In A File

You should note that the number of the current line is kept track off because Perl increments a counter each time it reads a line. Perl does that by basically looking at each byte of the input and when it has found the end of the line (what's in $/), it has read a line, and the counter can be incremented.

But when you seek to a certain position, Perl does not look at the bytes before the position you seek to (otherwise, seeking wouldn't be fast), so it has no way of knowing which line it is. Don't forget that on many systems, including Unix and Windows systems, files are just streams of bytes. The OS has no concept of lines.

If you must know the line numbers, what you can do is first you read the entire file, line-by-line, keeping track on which byte each line starts. You then have an index. Given the index, you can binary search to find the line number, given a position you seeked to.

Abigail