in reply to Re: Re: parsing comments in newline-delimited files as lists
in thread parsing comments in newline-delimited files as lists
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/#.*$//; next unless /([^\s]+)/; push(@enabled_lines, $1); }
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.while (<DATA>) { chomp; s/#.*$//; push @enabled_lines, $1 if /(\S+)/; }
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: parsing comments in newline-delimited files as lists
by Anonymous Monk on Dec 28, 2001 at 01:21 UTC |