in reply to Re: finding duplicates in an array
in thread finding duplicates in an array

Hi, thanx to both of you! I have made a mistake in my question.. what i have is an array of arrays that i want to make unique. That is, I have:
@AoA=(["1","15"], ["2","5"], ["3","4"], ["3","5"], ["3","8"], ["3","5"], ["4","6"], ["4","5"])
and I want to remove array element ["3","5"] which is seen twice if you notice. Is that possible?
  • Comment on Re^2: finding duplicates in an array--> WRONG QUESTION

Replies are listed 'Best First'.
Re^3: finding duplicates in an array--> WRONG QUESTION
by davorg (Chancellor) on Jan 27, 2006 at 10:57 UTC

    You just need to be a bit cleverer about the keys in your %seen hash.

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @AoA=(["1","15"], ["2","5"], ["3","4"], ["3","5"], ["3","8"], ["3","5"], ["4","6"], ["4","5"]); my %seen; @AoA = grep { ! $seen{join $;, @$_}++ } @AoA; print Dumper \@AoA;
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg