Hey there, perl monks blessed with wisdom from the HTML::Tree of knowledge. I'm having some trubbs with something. Some code, to be slightly more specific. I need to remove duplicates from an array. Easy you might say, and it's in the FAQs. However, after struggling with that solution for what seems like an age, I finally see the problem (and this is gonna sound really stupid). I'm not actually sorting a real array of elements, I'm sorting an array of hashes. Each containing two keys. Let us call them 'bob' and 'alice'. The array would look like this:
@array = [{bob => 'value1', alice => 'value2'}, {bob => 'othervalue1', + alice => 'othervalue2'}]; # and so on for loads of elements...
Obviously this wouldn't be very useful, but the hashes contain *swishes hands* top secret data. (Not really top secret; I just prefer to remain mysterious). So when I'm removing duplicates from this array, here's the crux of the matter. I need to remove the whole hash if only the 'bob' field is a duplicate, regardless of whether the 'alice' field is also a duplicate. So:
$hash = {bob => 'I am a value', alice => 'You're not a value.'}; $hash2 = {bob => 'I am a value', alice => 'You bloody well aren't a va +lue!'}
The second hash would be considered a duplicate of the first, the two bob fields being equal, and removed. Anyone up for suggesting how to do this? I'm pretty stumped.

--
my @words = grep({ref} @clever);
sub version { print "I cuss your capitalist pig tendencies bad!\n" }

In reply to Removing duplicate hashes based on only one key by Amoe

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.