且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-20 22:36:18

你可以像 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

如果您想使用模块,请尝试 uniq 功能code>List::MoreUtils

If you want to use a module, try the uniq function from List::MoreUtils