in reply to Fast way to read from file

If speed is important, don't even bother with a tied object. The tie mechanism is slow.

But your set_line routine utterly confuses me. Seeking goes to *byte* positions - it has no idea what a line means.

Abigail

Replies are listed 'Best First'.
Re: Re: Fast way to read from file
by Hena (Friar) on Nov 21, 2003 at 12:13 UTC
    But your set_line routine utterly confuses me. Seeking goes to *byte* positions - it has no idea what a line means.

    Well, since i know the line i'm currently and i know the line i want to be is smaller, i rewind the filehandle. Seek does that nicely (and fast, unless i'm mistaken).

    However i still read with readline(). Basicly that causes io for all line. Since io is slow and i don't really need the lines between 0 -> wanted (or current -> wanted), i think there should be a way to move faster between newlines *shrug*.
      A file is just a stream of bytes. A newline is a byte (or two on Windows) just like any other byte. There's no way to find a newline other than the read in the bytes until you find it.

      Now, if you can do preprocessing, you could build an index where lines start. Said preprocessing will take more time than going through the file once though.

      Abigail