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

Re: How do I make all the values in %a with common keys in %b equal to %b's keys?

by Roy Johnson (Monsignor)
on Nov 03, 2003 at 19:53 UTC ( [id://304228]=note: print w/replies, xml ) Need Help??


in reply to How do I make all the values in %a with common keys in %b equal to %b's values?

CharlesClarkson's can be written without the use of a temp or slices:

$a{$_} = $b{$_} for (grep exists $b{$_}, keys %a);

which also benchmarks a little better. For clarity, I like vroom's solution.

Note that if you know that one hash is much larger than the other, you will do better to iterate through the keys of the smaller hash and test exists against the larger.

  • Comment on Re: How do I make all the values in %a with common keys in %b equal to %b's keys?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-19 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found