$search_buffer="this text has teststring in it, it has a Test String too";
@waitfor=('Test string','some other string');
foreach my $test (@waitfor)
{
eval ('if (lc $search_buffer =~ lc ' . $test . ') ' .
'{' .
' $prematch = $`;' .
' $match = $&; ' .
' $postmatch = ' . "\$';" .
'}');
print "prematch=$prematch\n";
print "match=$match\n"; #I want to match both "teststring" and "Test String"
print "postmatch=$postmatch\n";
}
我需要打印測試字符串和測試字符串,你能幫忙嗎?謝謝。在Perl中用空格或無空格匹配字符串
你爲什麼使用['eval'](http://perldoc.perl.org/functions/eval.html)?這個代碼在「eval」之外幾乎以相同的方式工作。主要區別在於'eval'版本較慢,並且有潛在的安全漏洞。 –