【发布时间】:2014-01-06 22:36:44
【问题描述】:
这是一个代码sn-p:
$regex_match = "(.*).txt";
$replacement = "\$1.pdf";
my $new_replacement = ""; #???
my $new_regex_match = quotemeta ($regex_match); #???
$from = "test.txt";
(my $to = $from) =~ s{$regex_match}{$replacement}g;
print "From " . $from . " To " . $to . "\n";
输出: 从 test.txt 到 $1.pdf
我相信 $1 没有被插值。需要改变什么? new_replacement 和/或 new_regex_match 是什么?
【问题讨论】:
-
你为什么要逃避
$? -
您可以通过替换扩展名来简化代码:$from=~s/\.txt$/\.pdf/;