http://qs1969.pair.com?node_id=415899


in reply to Confessions of a back-alley map abuser

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 @_.

sub quux { my @args = @_; map { foo $_ } map { bar $_ } map { baz $_ } @args; }

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,
Zaxo

Replies are listed 'Best First'.
Re^2: Confessions of a back-alley map abuser
by Zed_Lopez (Chaplain) on Dec 19, 2004 at 00:56 UTC
    The Schwartzian Transform is on anybody's list of "Best Dressed Perl".

    Heh. Not the VP of Technology of a former workplace of mine who denounced an instance of the Schwartzian Transform in my code as "unreadable and unmaintainable." (It was commented as an ST, so any who didn't know it could look it up, but, of course, he already knew it was bad so he could save himself the bother of learning something new.)

    Of course, his idea of good Perl was Perl trying to look like Java...