这是 CPAN Uniq 模块中的错误吗?
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
是否应该是0A
?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用
uniq
函数来自List::MoreUtils
:
Uniq
模块版本为 0.1,仅发布过一个版本,那是在 2003 年。在选择模块时,请务必检查此类信息。具有多个版本(尤其是最近版本)的模块往往比只有一个或几个版本的模块更好。I would suggest using the
uniq
function fromList::MoreUtils
: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.我猜。这是 uniq 的源代码
第 6 行中的过滤器仅适用复制和 true 值,因此不会捕获重复的
"0"
值。为什么不提交错误报告?I guess. Here's the source code to uniq
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?这似乎与 CPAN 上报告的模块
Array::Uniq
的错误相同:Array::Uniq 不处理包含零值条目的数组。 Uniq 和 Array::Uniq 是包名称;我通过 .pm 文件的 unixdiff
证明了这一点。它们都是由同一作者创建的。该错误报告是 4 年前(2006 年)提交的,至今仍处于开放状态,作者从未回复过。作者应该删除这两个冗余模块之一。我认为可以合理地假设作者已停止维护这两个模块。使用其他答案提出的替代模块之一。
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 unixdiff
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.