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

Assuming %b has no null/empty/zero values:
for (keys %a) { $a{$_} = $b{$_} || $a{$_}; }
  • Comment on Re: How do I make all the values in %a with common keys in %b equal to %b's keys?
  • Download Code

Replies are listed 'Best First'.
(dkubb) Re: (2) Answer: How do I make all the values in %a with common keys in %b equal to %b's keys?
by dkubb (Deacon) on Mar 30, 2001 at 12:49 UTC

    Here's another way to do that:

    foreach my $key (keys %a) { $a{$key} = $b{$key} if exists $b{$key}; }

    or

    exists $b{$_} and $a{$_} = $b{$_} for keys %a;