This is a hash that can emulate duplicate keys. One module on CPAN allows you do this (and keep insertion order). It is Tie::DxHash. However my method allows you to add multiple values to one hash key, in essence, creating a hash that acts like it has duplicate keys. You can then check if your key has more than one value associated with it.
my %hash; # Assume a loop here that creates keys and values... my $key = 'alphabet'; my $letters = ['abc','def']; if (exists $hash{$key}) { my @letters_array = $hash{$key}; push @letters_array, $letters; my $new_val = [@letters_array]; $hash{$key} = $new_val; } else { $hash{$key} = $letters; } # Then check for "duplicate" keys (ie. a key with more than one value) +. for $key (keys %found_mod) { if (ref($found_mod{$key}[0]) eq 'ARRAY') { print "This key -- $key -- has more than one value!\n"; } }

In reply to Hashes with "duplicate" keys by jacques

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.