in reply to Re: Fast way to read from file
in thread Fast way to read from file

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*.

Replies are listed 'Best First'.
Re: Fast way to read from file
by Abigail-II (Bishop) on Nov 21, 2003 at 12:39 UTC
    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