in reply to Re^3: Finding unique elements in an array
in thread Finding unique elements in an array
So it looks like grep is the right tool.use List::Util 'reduce'; sub uniq { return @{;reduce {ref $a or $a=[$a]; push @$a, $b if $b ne $a->[-1 +]; $a} @_}; };
Update: This is a little shorter version with grep:
sub uniq { return @_ ? @_[0, grep {$_[$_] ne $_[$_-1]} 1..$#_] : (); };
|
|---|