in reply to Re: Best way to read line x from a file
in thread Best way to read line x from a file

Is it wasteful? - i.e. does such notation force perl to read in the whole file, or does it just read in the lines up to line x, or does it (we can but hope) somehow *just* read in line x?

Tom Melly, tom@tomandlu.co.uk
  • Comment on Re: Re: Best way to read line x from a file

Replies are listed 'Best First'.
Re: Re: Re: Best way to read line x from a file
by arden (Curate) on Mar 29, 2004 at 15:55 UTC
    No, seek() is not wasteful, however it doesn't really understand the concept of a line either. Seek basically blitzes its way to the location requested, so any future reads start from that location. You can also use seek to go backwards in a file too. But again, it doesn't work on the principle of "lines", instead it works on "byte offsets". That's why in your case it would only work if every line is of the same length.

    - - arden.
    arden is more of an orangutan than a monkee