Your questions was why the FAQ solution was preferred to another method that you described - other people have already answered and gave benchmark data to support it.

The only reason I am contributing to what seems like a complete thread is because I ran into a similar dilema that had real world impact. In trying to solve my problem (which is too long to get into here), I decided to check out the Unix Reconstruction Project at Perl Power Tools and found that the tcgrep was blazing fast in comparison to anything I was capable of writing.

I spent several days ripping out lines of code until I found what I was looking for and splicing it into my code with a few more optimizations for my very specific environment and was able to actually beat the compiled Unix grep (albeit in a very specific race).

So - if you are trying to count lines, words, characters, paragraphs, or a few other things - I would suggest checking out this.

UPDATE: PPT's port of wc does not use the ultra streamlined version of counting lines in a file, but it does offer all kinds of other support such as UTF support for word counting, etc - that is why I felt it was worth mentioning!

Cheers - L~R


In reply to Re: How To Count Lines In File? by Limbic~Region
in thread How To Count Lines In File? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.