我想使用变量作为 perl (s//) 中的替换文本?显然,以下代码不起作用。有没有办法做我想做的事?
~$ ./subsuffix.pl
xxx_$1_outsuffix.txt
subsuffix.pl:
#!/usr/bin/env perl
use strict;
use warnings;
my $filename="xxx_5p_insuffix.txt";
my $insuffix="_((5|3)p)_insuffix.txt";
my $outsuffix = '_$1_outsuffix.txt';
#result of the following is what I expect
#$filename =~ s/$insuffix$/_$1_outsuffix.txt/;
#But I want used a variable as the substitution text.
#Unfortunately, the following do not work.
$filename =~ s/$insuffix$/$outsuffix/;
print "$filename\n";