In perlfaq5, there\'s an answer for How do I count the number of lines in a file?. The current answer suggests a sysread
and a tr/\\n//
. I wanted to tr
Long lines are about 65 times larger than short lines, and your numbers indicate that tr/\n// runs exactly 65 times slower. This is as expected.
wc evidently scales better for long lines. I don't really know why; perhaps because it is tuned to just count newlines, especially when you use the -l
option.