如何从Perl中的数组中删除重复的项目?
发布时间:2020-12-15 21:29:41 所属栏目:大数据 来源:网络整理
导读:我有一个数组在Perl: my @my_array = ("one","two","three","three"); 如何从数组中删除重复项? 解决方法 你可以做这样的事情,如 perlfaq4所示: sub uniq { my %seen; grep !$seen{$_}++,@_;}my @array = qw(one two three two three);my @filtered = un
我有一个数组在Perl:
my @my_array = ("one","two","three","three"); 如何从数组中删除重复项? 解决方法
你可以做这样的事情,如
perlfaq4所示:
sub uniq { my %seen; grep !$seen{$_}++,@_; } my @array = qw(one two three two three); my @filtered = uniq(@array); print "@filteredn"; 输出: one two three 如果要使用模块,请尝试使用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |