I try to replace directory part of file fullname in Perl.
Something like:
got filename ‘D:\Texts1\text1’ in directory ‘D:\Texts1’, want to replace it with ‘D:\Texts2’ and then filename will be ‘D:\Texts2\text1’.
I try this code:
$filename = 'D:\Texts1\text1';
$i = 'D:\Texts1';
$o = 'D:\Texts2';
$filename =~ s'$i'$o'g;
And it does not take effect. $filename doesn’t changes.
I tried to use something like
$i = quotemeta('D:\Texts1');
but it also has not took effect.
this doesn’t interpolate
try using
/instead of', like this:that should work.
'prevents string interpolation, so the variable names appear as string literals. Also, make sure to use thequotemetalike you were doing before.