解决方案

查看perl的文档手册,

% perldoc -q duplicate

发现我们可以执行以下操作:

sub uniq {
    my %seen;
    grep !$seen{$_}++, @_;
}

my @array = qw(one two three two three);
my @filtered = uniq(@array);

print "@filtered\n";

输出:

one two three

如果要使用模块,请尝试使用List :: MoreUtils中的Uniq函数。

或者使用哈希并将项目添加到哈希中

my %unique = ();
foreach my $item (@myarray)
{
    $unique{$item} ++;
}
my @myuniquearray = keys %unique;
如何从Perl中的数组中删除重复项?

我在Perl中有一个数组:

my @my_array = ("one","two","three","two","three");

如何从数组中删除重复项?

日期:2020-03-25 18:32:05 来源:oir作者:oir