Q:

How to avoid duplicate values in an array of arrays?

I know how to avoid duplicates in a one-dimensional array. 
However, I have an array of arrays, and two lines of it may hold arrays with different references, but same values. I tried this:
sub unique {
     my %seen;
     grep !$seen{join('',$_)}++, @_ 
}

my @aa = (  ["1","2","3"],["1","2","3"],["1","2","4"] );
my @bb = unique(@aa);
print $_ for (@bb);

It should remove one of the two "123" arrays, but it doesn't. Probably because $_ holds a reference and not an array that can be joined? Of couse, I could loop through the $_ referenced array and concat all values, then use that as key to the %seen hash.
But I suspect there is a very elegant solution in Perl that I don't yet know of...

A:

To fix your naive approach, you should dereference the array references in two places: when serializing and when printing:
# Assumes the elements don't contain the value of $; (0x1C by default)
sub unique {
     my %seen;
     grep ! $seen{ join $;, @$_ }++, @_
}

my @aa = (  ["1","2","3"],["1","2","3"],["1","2","4"] );
my @bb = unique(@aa);
print "@$_\n" for (@bb);

This could still give wrong output, imagine [ "1\x{1C}2", 3 ]. More complex stringification is needed if your data could contain such strings. Fortunately, Perl already has a way to serialize array references: Data::Dumper:
use Data::Dumper;

sub unique {
    my %seen;
    grep ! $seen{ Dumper $_ }++, @_
}

