You pushed my "
$1 used outside the context of a conditional" button here.
That'd be failed in a code review if I were running the show. And yes, after I stared
at the code for a minute or so, I can see that the assertion from the previous line
ensures that there's always a match. But in that case, why not make the match,
the match!
while (<DATA>) {
chomp;
s/#.*$//;
next unless /([^\s]+)/;
push(@enabled_lines, $1);
}
There: it's now clear to me that we can't get to the push unless the match succeeds. I'd let this stand in a code review, but if I was looking for further optimization, I'd
just keep pressing forward for more clarity:
while (<DATA>) {
chomp;
s/#.*$//;
push(@enabled_lines, $1) if /([^\s]+)/;
}
Nicer. Tighter. Dare I say, "faster" as well? But I see some equivalances
that are down in the "nice" category (first was "must", second was "want",
now "nice"):
while (<DATA>) {
chomp;
s/#.*$//;
push @enabled_lines, $1
if /(\S+)/;
}
There. Clean, maintainable, pretty. I don't know if this does what the original
poster wanted, but I didn't change the meaning at all from the node to which
I'm replying.
-- Randal L. Schwartz, Perl hacker
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.