It accommodates for multiple key/values in data2.
It accommodates multiple hashes in $data2 with each hash having multiple key/values! This exceeds the implied requirement of the OP, but I find that requirements tend to expand spontaneously in these situations anyway.
I was a bit daunted by the time-complexity of the triple nesting of your solution. I tried to come up with some alternatives. I think these all work, but neither your solution nor any of mine have been thoroughly tested by me. Unfortunately, I think the big-Os of all these solutions, yours and mine, are going to turn out to be exactly the same!
foreach my $hashref (@$data1) { %$hashref = (%$hashref, %$_) for @$data2; } for my $hash1 (@$data1) { @{ $hash1 }{ keys %$_ } = values %$_ for @$data2; } foreach my $hash1 (@$data1) { for my $hash2 (@$data2) { map { $hash1->{$_} = $hash2->{$_} } keys %$hash2; } } for my $hash1 (@$data1) { for my $hash2 (@$data2) { while (my ($k2, $v2) = each %$hash2) { $hash1->{$k2} = $v2; } } }
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Insert into element into arrays ref
by AnomalousMonk
in thread Insert into element into arrays ref
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |