The following is a variant for references:
use strict; use warnings; use Data::Dump qw/pp dd/; my $h1 = { 'Tim' => { 'abc' => 7, 'def' => 7, 'ghi' => 0 }, 'Adam' => { 'abc' => 0, 'def' => 0, 'ghi' => 0 }, 'keas' => { 'abc' => 0, 'def' => 0, 'ghi' => 0 } }; my $h2 = { 'Dav' => { 'jkl' => 12, 'mno' => 34, 'pqr' => 45 }, 'Adam' => { 'jkl' => 7, 'mno' => 0, 'pqr' => 7 } }; my %joined_1st = (%$h1,%$h2); #pp \%joined_1st; my $joined_2nd = { map { $_ => { %{ $h1->{$_} // {} }, %{ $h2->{$_} // {} } } } keys %joined_1st }; pp $joined_2nd;
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
In reply to Re^3: How to combine two different hashes into single hash.
by LanX
in thread How to combine two different hashes into single hash.
by Sami_R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |