in reply to How To Count Lines In File?


The FAQ method is more efficient because it is reading in fixed block sizes which it doesn't have to split into lines.

Here is a benchmark to show the difference. I added wc for comparison:

$ time wc -l bigfile 91420 bigfile real 0m0.016s user 0m0.010s sys 0m0.006s $ time perl faq.pl bigfile 91420 real 0m0.032s user 0m0.027s sys 0m0.004s $ time perl cody.pl bigfile 91420 real 0m0.105s user 0m0.098s sys 0m0.008s

Here is the way I usually don't do it, this is twice as slow as the slowest method above:     perl -le 'print $==()=<>' file

--
John.

Update: Added benchmark.