Есть ли лучший способ сопоставить слова, отличные от этого метода, я пытаюсь найти слово в массиве, встречающееся в любом из предложений.
my $count = 0;
my @strings = (
"i'm going to find the occurrence of two words going if possible",
"i'm going to find the occurrence of two words if impossible",
"to find a solution to this problem",
"i will try my best for a way to match this problem"
);
@neurot = qw(going match possible);
my $com_neu = '\b'.join('\b|\b', @neurot).'\b';
foreach my $sentence (@string){
@l = $sentence =~ /($com_neu)/gi;
foreach my $list (@l){
if($list =~ m/\w['\w-]*/){
print $list;
$count++;
}
}
print $count;
}
Выход:
String 1: going going possible
String 2: going
String 3:
String 4: match
Пожалуйста, помогите мне быстрее.
Спасибо.