Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 surveying the Monastery: (7)
As of 2014-10-02 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls