M
Mithras
Hi all,
I want to use the substitution operator with variables rather than
string literals -- no problem, right?
My problem comes when I try to use the $1, $2, etc. variables to refer
to the matched expressions.
For example:
$pattern_to_match = 'I am (.*)';
$pattern_to_replace = 'You are $1';
$line =~ s/$pattern_to_match/$pattern_to_replace/g;
For example, if $line contains 'I am green', I want it to be replace
with 'You are green'.
However, the code fragment above would result in 'You are ' -- the $1
variable doesn't work as the match substitution...
Can anyone help me out?
I realize I may be able to work something out with the s///e option,
but this looks a little too complex for what I want to do.
TIA
I want to use the substitution operator with variables rather than
string literals -- no problem, right?
My problem comes when I try to use the $1, $2, etc. variables to refer
to the matched expressions.
For example:
$pattern_to_match = 'I am (.*)';
$pattern_to_replace = 'You are $1';
$line =~ s/$pattern_to_match/$pattern_to_replace/g;
For example, if $line contains 'I am green', I want it to be replace
with 'You are green'.
However, the code fragment above would result in 'You are ' -- the $1
variable doesn't work as the match substitution...
Can anyone help me out?
I realize I may be able to work something out with the s///e option,
but this looks a little too complex for what I want to do.
TIA