Is this a bug in the CPAN Uniq module?

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 

Should it be 0A or not ?!

thanks

+6
arrays perl unique
source share
3 answers

I would suggest using uniq 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 in version 0.1, has only one version, and that was in 2003. Always check that the information is sorted when choosing a module. Modules that have multiple releases (especially recent releases) tend to be better than modules that have only one or more releases.

+16
source share

I think. Here is the source code for 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 applies only to duplicate and true values, so duplicate values โ€‹โ€‹of "0" do not fall. Why would you send a bug report ?

+9
source share

This, apparently, is the same error reported in CPAN for the module Array::Uniq : Array :: Uniq does not process arrays containing entries with zero values . The only difference between Uniq and Array :: Uniq is the name of the package; I proved this with unix diff my .pm files. They were created by the same author.

This bug report was sent 4 years ago (2006), it is still open, and the author did not respond to it. The author should exclude one of these two redundant modules. I think it is reasonable to assume that the author has stopped supporting these two modules. Use one of the alternative modules suggested by the other answers.

+7
source share

All Articles