Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 studying the Monastery: (9)
As of 2015-07-04 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls