Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Confessions of a back-alley map abuser

by Zaxo (Archbishop)
on Dec 18, 2004 at 19:39 UTC ( [id://415899]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://415899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found