in reply to Fast Way to Return Unique Array of Array

Slightly modify the original uniq(), it works:

use Data::Dumper; my @AoA = (['a','b','c'], ['a','b','c'], ['a','b','d'], ['a','b','d']); my @uAoA = uniq(@AoA); print Dumper \@uAoA; sub uniq () { my %h; map { $h{join($;, @$_)}++ == 0 ? $_ : () } @_; }

Replies are listed 'Best First'.
Re^2: Fast Way to Return Unique Array of Array
by calin (Deacon) on Sep 05, 2005 at 10:17 UTC

    Nice, just a slight style improvement:

    map { $h{join($;, @$_)}++ == 0 ? $_ : () } @_;

    becomes

    grep { ! $h{join($;, @$_)}++ } @_;
      Could one replace join($;, @$_) with Dumper($_) (or some variant thereof), to allow for multiple levels of data structure?