in reply to finding duplicates in an array

You probably want to use grep along with a hash for removing duplicates from an array.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: finding duplicates in an array--> WRONG QUESTION
by Anonymous Monk on Jan 27, 2006 at 10:00 UTC
    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?

      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