To be honest, I don't consider this code that bad. Yes, there are some small issues - they mainly suggest the author is not a perl expert - but it seems unlikely that any of them would affect correct behaviour or cause significant performance issues in the context this code is likely to run.

My first concerns would rather be with two things you don't mention: that on failing to open the file for reading (most likely due to permissions), it fails to mention the name of the file it tried to open; and that it stuffs @ARGV with an arbitrarily long list of the words it found, which feels like a possible design flaw.

That last, however, suggests this configuration file is expected rarely to be more than a couple of lines long, so performance of the processing loop is really not likely to be very relevant.

Data is assigned to $_ and then copied to $line but $_ is never used inside the loop.

This is pretty reasonable if as a non-expert you are vaguely aware that while ($line = <$fh>) has some differences around termination conditions compared to while (<$fh>).

This is the line that gobsmacked me. I ran some tests with Benchmark and re 'debug' compared to the FAQ answer "s/\s+$//;" and it turns out that this is a good example of what not to do.

And how much CPU time do you think replacing it would save over the lifetime of the universe? I suspect the total would sit comfortably under a second, maybe even under a millisecond.


In reply to Re: Critique of some perl code. by hv
in thread Critique of some perl code. by jwkrahn

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.