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