Thank you Kennethk for reply. Sorry I forgot to add what I tried. I made a function to compare first level key and value of two hashes but I am struggling to check for second level values. Can you please help?
comp (\% hash1, \%hash2); sub comp { my $hash1 = shift; my $hash2 = shift; if( keys %{$hash1} != keys %{$hash2} ) { print "Hash1 has ", scalar(keys %{$hash1}), " units but hash2 has ", scalar(keys %{$hash2}), "\n"; } for my $key_hash1 (sort {lc($a) cmp lc($b) } keys %{$hash1} ) { if( ! exists $hash2->{$key_hash1} ) { print "Hash1 contains unit '$key_hash1' but hash2 has no such un +it\n"; next; } if( $hash1->{$key_hash1} ne $hash2->{$key_hash1} ) { print "Both hashes have '$key_hash1' as a unit ", "but hash1's value is '$hash1->{$key_hash1}' ", "and hash2's value is '$hash2->{$key_hash1}'\n"; } } }
In reply to Re^2: Compare two Hashes of Hashes
by Eshan_k
in thread Compare two Hashes of Hashes
by Eshan_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |