Hi Hauke D,

Your comments are well taken.
I certainly wouldn't say that there is anything wrong at all with using the single regex for trimming the lines.
A large amount of Perl that I write involves processing text files which come from various sources, sometimes cut-n-paste amalgamations generated by users. I can't think of any example where the "line trim" code or "skip blank line" code, e.g. next if /^\s*$/; played any significant performance role at all. Leaving a blank line in the file is so common that I almost always add that fast regex (its fast because of the anchors) to get rid of non-data lines.

Performance can be a very, very application specific thing. I wrote one program that took 4 hours to run. I got complaints as to the run time. I asked, "how many times per year do you run this program?". Answer: 4 times per year. I used algorithms that made it easy for me to develop/debug and track down any questionable decision(s) and also to come as close as I could to guaranteeing that it produced a correct result. Accuracy was my main goal. I never got an answer about why 4 hours mattered. New management ordered it to be recoded, with a goal of much faster at the expense of perhaps a 10% error rate. So the new version runs much faster, but makes more mistakes. Which is better? Depends upon what you want.

Algorithms and data structures make a lot more difference than this simple "what do I do with this single line" although I will admit to beating on a single critical important regex line for an entire week to squeeze some more performance out of it - if you do it a million times, it can matter a lot.


In reply to Re^5: Prototype mismatch: sub main::trim: none vs ($) by Marshall
in thread Prototype mismatch: sub main::trim: none vs ($) at mysqlDB_serial.pl line 188. by bNathan

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.