我想通过使用数组元素来匹配数据上的缺席单词。 我的代码是如何匹配perl中缺少数组元素?
use warnings;
use strict;
my @ar = qw(one two three four five six seven eight nine ten);
my @data = <DATA>;
print "Absence word in the data\n";
foreach my $mat(@ar){
my $nonmatch;
foreach my $dat (@data){
$nonmatch = grep{m/(?!$mat)/} $dat;
}
print "$nonmatch\n";
}
__DATA__
eight two four one two three four seven eight ten one two seven
首先参阅数据阵列元件上的阵列元素的值是在仅打印在数据不存在。
我预期成果是:
Absence word in the data
five
six
nine
我该怎么办呢
对于'@ data'中的单词使用散列,这样就可以检查散列中是否存在$ mat。 – 2014-09-26 17:12:16