The second answer may be incorrect. According to the question: we are to find all the matches between the keys in %a and %b, and if there is a match, assign the value of the matching element from %b into the corresponding element in %a.
A hash slice won't work in this case, consider:
my %a = ( a => 1, b => 2, c => 3, ); my %b = ( b => 4, d => 8, f => 12, ); @a{ keys %b } = values %b;
Now, %a is:
%a = ( a => 1, b => 4, c => 3, d => 8, f => 12, );
Which is the incorrect answer, according to the question. If we use a hash slice, we'll be copying all the elements from %b into %a, regardless if there are any matches, or not.
In reply to (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
in thread How do I make all the values in %a with common keys in %b equal to %b's values?
by draco_iii
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |