Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have two hashes of key-value pairs of numbers. I want to find out how many of these key-value pairs are the same and different in both hashes (matching in both orientations e.g. key-key and key-value etc).
I have some code sort of working but it only works out which keys are different (below). Can someone help me to extend my code to find out which key-value pairs are the same and where the differences are?
Kind regards.
my %old_gp = map {$gp1_a[$_] => $gp1_b[$_]} 0 .. $#gp1_a; my %new_gp = map {$gp2_a[$_] => $gp2_b[$_]} 0 .. $#gp2_a; + + my @diff=(); foreach (keys %new_gp) { push (@diff, "$_ ") unless exists $old_gp{$_}; } + print @diff;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing key-value pairs of two hashes
by blazar (Canon) on Jul 22, 2005 at 10:50 UTC | |
by Anonymous Monk on Jul 22, 2005 at 10:58 UTC | |
|
Re: comparing key-value pairs of two hashes
by polettix (Vicar) on Jul 22, 2005 at 11:18 UTC | |
by Codon (Friar) on Jul 22, 2005 at 16:21 UTC |