I am doing a find-replace on filenames which are 2 numbers then description. I need to transform the filenames. I would like the 2 parts of the substitution as variables (so that I can pass in on the command line). I show a cutdown version here. This works:
my $source = "(\\d\\d)(\.\*)" ;
$_ = "35 example filename.fmn";
s/$source/data $1/; # source substitution works
print("$_\n"); #prints 'data 35' correctly
... but this does NOT work:
my $source = "(\\d\\d)(\.\*)" ;
my $dest = "data $1";
$_ = "35 example filename.fmn";
s/$source/$dest/; # dest substitution does NOT work
print("$_\n"); #prints 'data'
It presumably does not work because $1 is substituted before the s///
I would be very grateful if someone could tell me how I can write the 'dest' variable so that it will work.
Thank you.
Jon
my $source = "(\\d\\d)(\.\*)" ;
$_ = "35 example filename.fmn";
s/$source/data $1/; # source substitution works
print("$_\n"); #prints 'data 35' correctly
... but this does NOT work:
my $source = "(\\d\\d)(\.\*)" ;
my $dest = "data $1";
$_ = "35 example filename.fmn";
s/$source/$dest/; # dest substitution does NOT work
print("$_\n"); #prints 'data'
It presumably does not work because $1 is substituted before the s///
I would be very grateful if someone could tell me how I can write the 'dest' variable so that it will work.
Thank you.
Jon