Welcome to the Monastery.

I apologize if I misinterpret your question. It's usually a good idea to provide sample data for what you want to do in order to clarify your question. See I know what I mean. Why don't you?.

Fundamental to the hash data structure is a unique key for every entry. Therefore, it is impossible to have a key occur more than once for the hash. If you attempt to store a key-value pair more that once, it will overwrite the old value with the new one, but there will still only be one occurrence of the key.

If, on the other hand, you are trying to check if a value already exists in a hash, that is answered in a faq. Assuming your data is in a hash named %hash, you could check if the value in $value already exists with the code:

my %reverse_hash = reverse %hash; if (not exists $reverse_hash{$value}) { $hash{$key} = $value; }

You could express that much more succinctly, but I expect that would confuse the issue. There are a few other ways I could think of interpreting your question, and so if these explanations do not answer your specific question, please provide some more specificity.


In reply to Re: Tie::Hash::MultiValue Unique question by kennethk
in thread Tie::Hash::MultiValue Unique question by elsubliminal

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.