Consider that's speed you're after: the answer is: use a different language than Perl.

I agree with many of your more controversial assertions; but that one is a gross over simplification.

For many things, especially text manipulations, well thought through Perl programs will run a highly tuned C program a very close second. And if you factor in the development time, maintainability and portability, they'll usually win hands down.

But the trick to good performance--as you well know and frequently demonstrate--is to write the Perl program in that way that best plays to its strengths. In general, that means avoiding the O'Woe trap and writing the simplest code that gets the job done.

Just because someone is prepared to spend an extra hour or two to get the best performance available from their perl script, it does not mean it warrents spending a week or two trying to write and tune the equivalent C(Java/Other) program.

In this case, as GrandFather points out, making two passes of each line rather than one, will likely make very little difference. Assuming that is the total extent of the processing required between reading and writing each record. But that is not always the case, and becoming familiar with which Perl techniques are more efficient than others is as good a function of this place as any other.

Asking certainly should not be cause for your derision, just because you know that in this case the suggested alternatives are unlikely to be of benefit. Much less because you are sufficiently experienced to consider writing things in other languages when you consider that would be advantageous to your needs. Many who come here do not readily have that option. And others would prefer to avoid it where possible,


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: timtowtdi but which is the [quote fingers]best[/quote fingers] by BrowserUk
in thread timtowtdi but which is the [quote fingers]best[/quote fingers] by PyrexKidd

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.