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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.