Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: map2 {} grep2 {} ...

by duelafn (Priest)
on Jul 14, 2011 at 18:45 UTC ( #914410=note: print w/ replies, xml ) Need Help??


in reply to map2 {} grep2 {} ...

I think it looks better if one makes use of $a and $b

sub map2(&@) { my $f = shift; my @res; no strict 'refs'; my $caller = caller; local(*{$caller."::a"}) = \my $a; local(*{$caller."::b"}) = \my $b; if (defined(wantarray)) { push @res, $f->($a,$b) while ($a, $b) = splice @_, 0, 2; return @res; } else { $f->($a,$b) while ($a, $b) = splice @_, 0, 2; } } # ... %h_prefixed = map2 { ($a, "p$b") } %h; @a_hashed = map2 { +{ $a => $b } } @a;

Good Day,
    Dean


Comment on Re: map2 {} grep2 {} ...
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-07-13 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls