0

我给 $second 变量为: E:\oracle\V44\EBSapps\appl\admin\adalldefaults.txt<br/>

两个字符串都相同,但通过该运算符,它们不匹配。为什么?

my $first="E:\\oracle\\V44\\EBSapps\\appl\\admin\\adalldefaults.txt";
chomp(my $second=<STDIN>);

print "$first\n";
print "$second\n";
print length($first);print "\n";
print length($second);print "\n";

if ($first !~ /$second/i)
{
    print "string didn't matched\n";
}
else
{
    print "string matched\n";
}
4

1 回答 1

2

利用

$first !~ /\Q$second\E/i

\Q应用quotemeta引用所有特殊字符的函数,直到\E.

于 2013-04-08T09:23:00.293 回答