我有一个 Perl 数组:
my @my_array = ("one","two","three","two","three");
如何从数组中删除重复项?
最佳答案
您可以执行类似的操作,如 perlfaq4 中所示。 :
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
函数
关于perl - 如何从 Perl 数组中删除重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7651/