如何替換變量內的反斜槓?用Perl中變量中的反斜槓替換文字
$string = 'a\cc\ee';
$re = 'a\\cc';
$rep = "Work";
#doesnt work in variable
$string =~ s/$re/$rep/og;
print $string."\n";
#work with String
$string =~ s/a\\cc/$rep/og;
print $string."\n";
輸出:
a\cc\ee
Work\ee
使用單引號是好的。在這種情況下,不需要插入字符串。 – Ether 2010-06-03 19:53:15