in reply to Re: Re: Fast way to read from file
in thread Fast way to read from file
Expose this function in Perl, so that you can doseek_line(FILE *f, long lineno) { char buffer[65536]; # 64k buffer fseek(f, 0, SEEK_SET); // read in 64 k of text at a time fread(buffer, 65536, 1, f); // then count number of \n's // if found the desired number of lines, then // record the position found, fseek to that // position in file, and then return // if not enough lines, read next block of 64k text // and repeat until you have the desired number of // lines. fseek to the absolute position in file // for the desired line, and then return }
seek_line($fh, $line_no); # and then read as normal
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Fast way to read from file
by broquaint (Abbot) on Nov 21, 2003 at 14:53 UTC |