in reply to Eliminate Array of array duplication

For each reference, create a signature string. Two references you consider different must have different signatures. Two references you consider identical must have identical signatures. Use a hash keyed by these signatures to identify duplicates.

my %seen; @AoD = grep !$seen{ join(',', @$_) }++, @AoD;

Replies are listed 'Best First'.
Re^2: Eliminate Array of array duplication
by Utilitarian (Vicar) on May 19, 2011 at 08:32 UTC
    I would agree with ikegami's post above, the only thing I'd add it that you should probably sort the array before using it as a key, if [1, 2, 3] , [3, 2, 1] and [2, 1, 3] are considered identical.
    my %seen; @AoD = grep !$seen{ join(',', (sort {$a<=>$b} @$_ )) }++, @AoD;
    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      Indeed. If one desires for [1,2,3] and [3,2,1] to be considered identical, they must have identical signatures, and that can be achieved by sorting the numbers.

      I doubt that's going to be a common desire, but if it happens, it's probably cleaner to normalise the data before finding the dups.

      # Normalise the data. @$_ = sort { $a <=> $b } @$_ for @AoD; # Filter out duplicates. my %seen; @AoD = grep !$seen{ join(',', @$_) }++, @AoD;