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

Maybe I'm missing something but when I try this code I get the following results on an AIX box using timex:

real 10.10
user 8.02
sys 1.00

Whereas, if I just do something "simple" like:

open IN, '<test.dat' or die $!;
while (<IN>) {
{increment counter, if counter is 500000, return results}

I get:

real 1.70
user 1.44
sys 0.06

???

Replies are listed 'Best First'.
Re: Re: Re: Fast way to read from file
by BrowserUk (Patriarch) on Nov 21, 2003 at 18:47 UTC

    From my understanding of the OP's post. His requirements were that he should be able to randomly access the file by line number.

    It will obviously be slower than a simple sequential read of the file as it has to do that once in order to build teh index. It is only when subsequent use is made to re-read individual records in random order that it will be beneficial.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!