M
Mr P
I'm trying to process strings like:
cat_7 becomes dog_7....
so for the general numeric case it's something like
s/cat_(\d)/dog_$1/;
However, I don't know what string I may be asked to match/substitute
on. Therefore I'm trying to store the LHS and RHS in a var, and
evaluate them:
$k = 'cat_(\d+)';
$k2 = 'dog_$1';
$line =~ s/$k/$k2/e;
The LHS seems ok- it properly finds a like like cat_7. However, the RHS
does not substitute the value of $1- instead it always produces
'dog_$1' instead of 'dog_7'.
I tried some other regex switches too. I also read the Perlre info
where it says the RHS is interpreted as a double-quoted string. Oddly,
this seems to be a single-quoted string to me.
Can someone please tell me what I'm missing? I thought the /e would
tell it to evaluate $1 ?
Thank-You and Happy Holiday,
Mister P
cat_7 becomes dog_7....
so for the general numeric case it's something like
s/cat_(\d)/dog_$1/;
However, I don't know what string I may be asked to match/substitute
on. Therefore I'm trying to store the LHS and RHS in a var, and
evaluate them:
$k = 'cat_(\d+)';
$k2 = 'dog_$1';
$line =~ s/$k/$k2/e;
The LHS seems ok- it properly finds a like like cat_7. However, the RHS
does not substitute the value of $1- instead it always produces
'dog_$1' instead of 'dog_7'.
I tried some other regex switches too. I also read the Perlre info
where it says the RHS is interpreted as a double-quoted string. Oddly,
this seems to be a single-quoted string to me.
Can someone please tell me what I'm missing? I thought the /e would
tell it to evaluate $1 ?
Thank-You and Happy Holiday,
Mister P