Oh, heh. Delete non-duplicates. Right, sorry. :)

Anyway, what you have posted works fine (which is what I thought initially, before I got confused about which you were wanting to remove).

[johnsca@CORY tmp]$ cat tst.pl #!/usr/bin/perl my @Tapes = ( ['Label 1', 'p', 'l', 'P'], ['Label 1', 'p', 'l', 'P'], # Duplicate ['Label 2', 'p', 'l', 'P'], ['Label 3', 'p', 'l', 'P'], ); hash_tapes(@Tapes); sub hash_tapes (@) { my @tapes = @_; my %Tape_Cat =(); foreach my $tape (@tapes) { my ( $label, $protection, $location, $pool ) = @{$tape}; push @{ $Tape_Cat{$label} }, [ $protection, $location, $pool ] +; } # Get rid of non-duplicates my $count = 0; foreach my $tape (@tapes) { my ($label,$protection,$location,$pool) = @{$tape}; if ( @{$Tape_Cat{ $label}} < 2 ) { print "Deleting ". $label. "Because it has ".@{$Tape_Cat{ $label }}. " record(s)\n"; $count++; delete $Tape_Cat{$label} } } my @keys = keys %Tape_Cat; print "Deleted $count keys, keys: @keys\n"; return \%Tape_Cat; } [johnsca@CORY tmp]$ ./tst.pl Deleting Label 2Because it has 1 record(s) Deleting Label 3Because it has 1 record(s) Deleted 2 keys, keys: Label 1

Correct, no? You should probably double-check the data that this function is actually getting. Use Data::Dumper at the begining of the function, or the built-in perl debugger. Update: If the data is coming from an outside source, check for strange things like leading or trailing newlines or linebreaks, or non-printable characters, or such.

Good luck. :)

bbfu
Black flowers blossum
Fearless on my breath


In reply to (bbfu) (oops) Re2: (bbfu) Re: Hmmm... HoA help ... by bbfu
in thread Hmmm... HoA help ... by talwyn

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.