使用未初始化值的我想不通,为什么正则表达式模式不匹配。此外,输出抱怨$found
未初始化,但我相信我是这样做的。这是我到目前为止的代码:Perl的警告:(。)的串联或串
use strict;
use warnings;
my @strange_list = ('hungry_elephant', 'dancing_dinosaur');
my $regex_patterns = qr/
elephant$
^dancing
/x;
foreach my $item (@strange_list) {
my ($found) = $item =~ m/($regex_patterns)/i;
print "Found: $found\n";
}
这里是输出我得到:
Use of uninitialized value $found in concatenation (.) or string at C:\scripts\perl\sandbox\regex.pl line 13.
Found:
Use of uninitialized value $found in concatenation (.) or string at C:\scripts\perl\sandbox\regex.pl line 13.
Found:
我需要以另一种方式来初始化$found
?此外,我正确地创建一个多行字符串解释为正则表达式?
非常感谢。
你多行字符串被解释为'QR /大象$ ^跳舞/;'而你可能想'QR /大象$ | ^跳舞/; ' – user1937198
对于多行匹配,使用/ m开关:'我的$ regex_patterns = QR /大象$ ^跳舞/ MX;' – shawnhcorey