use Uniq;
my @test1 = ("0","0","A");
my @test2 = ("1","1","A");
@test1 = uniq sort @test1;
@test2 = uniq sort @test2;
print "$_" for @test1;
print "\n";
print "$_" for @test2;
print "\n";
returns :
00A
1A
It should be 0A or not?!
Thank you
I would suggest using the uniq
function from List::MoreUtils
:
use strict;
use warnings;
use List::MoreUtils qw/uniq/;
my @test1 = uniq qw(0 0 A);
my @test2 = uniq qw(1 1 A);
print "@test1\n@test2\n";
The Uniq
module is at version 0.1, has had only one release, and that was back in 2003. Always check for the that sort of information when selecting a module. Modules that have multiple releases (especially recent releases) tend to be better than modules that have only one or a few releases.
I guess. Here's the source code to uniq
1: sub uniq{
2: # Eliminates redundant values from sorted list of values input.
3: my $prev = undef;
4: my @out;
5: foreach my $val (@_){
6: next if $prev && ($prev eq $val);
7: $prev = $val;
8: push(@out, $val);
9: }
10: return @out;
11: }
The filter in line 6 only applies to duplicate and true values, so duplicate "0"
values are not caught. Why don't you submit a bug report?
This appears to be the same bug reported on CPAN for module Array::Uniq
: Array::Uniq doesn't handle arrays containing entries with zero values. The only difference between Uniq and Array::Uniq is the package name; I proved this by a unix diff
of their .pm files. They were both created by the same author.
That bug report was submitted 4 years ago (2006), it is still open, and the author never replied to it. The author should eliminate one of these two redundant modules. I think it is reasonable to assume the author has stopped maintaining these two modules. Use one of the alternative modules proposed by the other Answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With