Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: map2 {} grep2 {} ...

by betterworld (Deacon)
on Jul 14, 2011 at 17:30 UTC ( #914401=note: print w/ replies, xml ) Need Help??


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

The solutions offered so far are very sophisticated, but I think the most stupid way is also the most readable:

my %h_prefixed; my %h_numbers; while(my ($key, $val) = each %h) { $h_numbers{$key} = $val if looks_like_a_number($val); $h_prefixed{$key} = "p$val"; }

And it's (probably) not even slower or anything.

For a (maybe a bit) less readable solution, I'd like to offer the following:

my %h_prefixed; @h_prefixed{keys %h} = map "p$_", values %h;


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://914401]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-09-19 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls