in reply to How do I make all the keys in %a with common keys in %b equal to %b's values?
for (keys %a) { $a{$_} = $b{$_} if exists $b{$_}; } # or for (keys %b) { $a{$_} = $b{$_} if exists $a{$_}; } # or $a{$_} = $b{$_} for grep { exists $b{$_} } keys %a; # or $a{$_} = $b{$_} for grep { exists $a{$_} } keys %b;
(whether to iterate over keys %a or keys %b is essentially arbitrary — pick the one with fewer keys (if known beforehand) )
|
|---|