This sounds like homework to me and I'll answer it as if that is the case.
What you are trying to do, if I have it correct, is to take N hashes and establish where they share the same key values.
If you ignore the fact that they are hashes for a minute you can effectively separate Perl syntax from the actual problem itself. So you actually have two questions, how do you loosely define a data structure that has the information you want that you can use and, afterward, to write it in Perl.
Here I'll show one way to do it which is pretty (purposefully) verbose but works:
sub dump_hash_maker { my ($ltrStart, $size) = @_; my $stop = chr (ord($ltrStart)+$size); my @letters; push @letters, $_ for ($ltrStart..$stop); my %hash = map {(shift @letters)=>$_} (1..$size) ; return %hash; } my %hash1 = dump_hash_maker('A',4); my %hash2 = dump_hash_maker('D',7); my %hash3 = dump_hash_maker('J',13); my @allkeys = (); my (%intermediate); push @allkeys,(keys %hash1); push @allkeys,(keys %hash2); push @allkeys,(keys %hash3); for(@allkeys) { $intermediate{$_}++; } for(keys %intermediate) {print $_ if $intermediate{$_} > 1}; # prints JD
You'll see that I dumped all of the individual keys into one big array and then folded that into a hash by incrementing the number of times it occurs. There are much smaller examples of this in Perl books. Another approach would have been to build a larger data structure and then write a (recursive?) function that would return nodes with a depth > 1.
Celebrate Intellectual Diversity
In reply to Re: Comparing three Hashes
by InfiniteSilence
in thread Comparing three Hashes
by shivnani_s
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |