我想通過使用數組元素來匹配數據上的缺席單詞。 我的代碼是如何匹配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