Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have two different hashes. One has three values per key (triplet), the other has two values per key (doublet). Both hashes are comprised of similar entries, e.g. where @A1 and @A2 may have duplicate matches in them.
I am trying to compare both hashes to find key-value-value pairings in the doublet that do not appear in the triplet. I have something like this so far, which checks for the presence of keys in the hash. However, I am not sure how to scale this up to check for all three values in %doublet in the %triplet and then print out any rows that are missing.
I hope that someone can advise!
my %triplet = map {($A1[$_] => [$B1[$_], $C1[$_], $D1[$_]]) } 0..$#tri +plet; my %doublet = map {($A2[$_] => [$D2[$_], $C2[$_]])}0..$#doublet; for (my $i=0; $i<@A2; $i++) { if (exists($triplet{$A2[$i]})) { print "$A2[$i]\n"; } else { } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing values in two hashes
by graff (Chancellor) on Feb 14, 2006 at 02:18 UTC | |
|
Re: comparing values in two hashes
by ayrnieu (Beadle) on Feb 13, 2006 at 22:36 UTC |