my @my_array = ("one","two","three","three");
如何从数组中删除重复项?
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函数
List::MoreUtils