in reply to How can I display a unique array if it contains some repeated elements
a sub to get both unique and not:
@array1 = (1,1,2,3,3,4); #unique print unique(@array1); #not print unique(\@array1); sub unique{ my (%seen, $array); ($array)=@_; if(@$array){return grep{$seen{$_} ++} @$array;} else{return grep{ ! $seen{$_} ++} @_;} }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: How can I display a unique array if it contains some repeated elements
by halley (Prior) on Aug 14, 2003 at 21:47 UTC |
In Section
Seekers of Perl Wisdom