![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
Re: Confessions of a back-alley map abuserby Zaxo (Archbishop) |
on Dec 18, 2004 at 19:39 UTC ( #415899=note: print w/replies, xml ) | Need Help?? |
You've put your chaining at a disadvantage in the ugliness department by illustrating it with mutators of $_. This technique shines in combination with other list operators like grep and sort, and when wrapped in a subroutine so that it acts on a copy of @_.
The real alternative is nested sub calls. While those look messy in C, with all the parens to be balanced, they have an equally nice expression in Perl, my $quux = foo bar baz $_; One of the better reasons to use map in this way is the aliasing of localized $_ to each argument in turn. That is not a big advantage in your actions on a list of one element, but is a nice shorthand when operations act on $_ by default. You missed an opportunity to use that in the map { uc } stage. Of course, this is all extremely powerful when acting on lists. The Schwartzian Transform is on anybody's list of "Best Dressed Perl". After Compline,
In Section
Meditations
|
|