是什么在使用Perl数据数组重复检查的最有效方法是什么? [英] What's the most efficient way to check for duplicates in an array of data using Perl?
本文介绍了是什么在使用Perl数据数组重复检查的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要看看是否有一个字符串数组重复的,什么是做它的时间最有效的方法是什么?
解决方案
一个我喜欢的Perl的事情之一是它几乎像读英语的能力。它只是排序是有意义的。
使用严格的;
使用警告;我@array = QW /是否也许真虚假也许没有/;我见过%;我的foreach $字符串(@array){ 除非旁边看到$ {$ string}里++;
打印'$字符串'被复制\\ n;
}
输出
'假'是重复的。
'不'是重复的。
块引用>I need to see if there are duplicates in an array of strings, what's the most time-efficient way of doing it?
解决方案One of the things I love about Perl is it's ability to almost read like English. It just sort of makes sense.
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"; }
Output
'false' is duplicated.
'no' is duplicated.
这篇关于是什么在使用Perl数据数组重复检查的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文