这是 CPAN Uniq 模块中的错误吗?

发布于 2024-09-28 17:47:51 字数 298 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-10-05 17:47:51

我建议使用 uniq 函数来自 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";

Uniq 模块版本为 0.1,仅发布过一个版本,那是在 2003 年。在选择模块时,请务必检查此类信息。具有多个版本(尤其是最近版本)的模块往往比只有一个或几个版本的模块更好。

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.

傾旎 2024-10-05 17:47:51

我猜。这是 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: }

第 6 行中的过滤器仅适用复制和 true 值,因此不会捕获重复的 "0" 值。为什么不提交错误报告

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?

时光倒影 2024-10-05 17:47:51

这似乎与 CPAN 上报告的模块 Array::Uniq 的错误相同:Array::Uniq 不处理包含零值条目的数组UniqArray::Uniq 是包名称;我通过 .pm 文件的 unix diff 证明了这一点。它们都是由同一作者创建的。

该错误报告是 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文