Syntactic Confectionery Delight | |
PerlMonks |
Re: Best way to read line x from a fileby Corion (Patriarch) |
on Mar 29, 2004 at 15:34 UTC ( [id://340640]=note: print w/replies, xml ) | Need Help?? |
I think that Tie::File is the best compromise between speed and simplicity for such tasks. The fastest way would be a loop like the following, assuming that the line indicated by $line_no will start in the first half of the file:
as then, Perl and the OS will do some buffering for you, and you don't read the whole file for nothing. If your file size is smaller than one sector, the OS (and the HD) will read it into memory anyway, and it might be faster to slurp it into memory and use a crafted regular expression against it:
So in the end, you will have to benchmark a lot.
In Section
Seekers of Perl Wisdom
|
|