in reply to Re: PerlCritic, $_ and map
in thread PerlCritic, $_ and map
what do you think about this alternative?Quite bad actually. s/^\s+//; s/\s+$//; is common idiom enough that people instantly see what is being done (it is for instance mentioned in the perlfaq) - your solution requires more thinking to see what it does.my @files = map { /^\s*(\S.*?)\s*$/ && $1 || "" } <$FILES>;
And then there's performance.
use Benchmark 'cmpthese'; our @data = ('foo', 'foo bar', ' foo', 'foo ', ' foo ', ' foo bar '); + cmpthese -1, { faq => 'for my $x (@::data) {$_ = $x; s/^\s+//; s/\s+$//}', Skeeve => 'for my $x (@::data) {$_ = $x; $_ = /^\s*(\S.*?)\s*$/ && $ +1 || ""}' }; __END__ Rate Skeeve faq Skeeve 19139/s -- -68% faq 59077/s 209% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: PerlCritic, $_ and map
by Skeeve (Parson) on Feb 13, 2009 at 16:06 UTC |