Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: map2 {} grep2 {} ...

by duelafn (Vicar)
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

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 rifling through the Monastery: (7)
As of 2016-10-01 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (6 votes). Check out past polls.