加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

数组 – 使用Perl检查数据数组中的重复项最有效的方法是什么?

发布时间:2020-12-15 21:20:16 所属栏目:大数据 来源:网络整理
导读:我需要看一下字符串数组中是否存在重复项,最有效的方法是什么? 解决方法 我喜欢Perl的事情之一就是能够像英语一样读书。这只是一种有意义的东西。 use strict;use warnings;my @array = qw/yes no maybe true false false perhaps no/;my %seen;foreach my
我需要看一下字符串数组中是否存在重复项,最有效的方法是什么?

解决方法

我喜欢Perl的事情之一就是能够像英语一样读书。这只是一种有意义的东西。
use strict;
use warnings;

my @array = qw/yes no maybe true false false perhaps no/;

my %seen;

foreach my $string (@array) {

    next unless $seen{$string}++;
    print "'$string' is duplicated.n";
}

产量

'false' is duplicated.

'no' is duplicated.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读