T
Tyson Marchuk
Sorry if this has been asked before but there are over 12k messages in this
group... none of my searches on the group turned up the answer to this.
Basically I was wondering how I can use a variable as the replacement in a
substituion.
ie. I want to do something like this:
$lineToBeReplaced =~ s/$searchString/$replaceString/;
Where $searchString and $replaceString are defined at run-time. The
$searchString seems to work fine but I can't seem to get the $replaceString
to work with backreferencing metacharacters. (eg. $1, $2 or \1, \2) Instead
if $replaceString is "$1" for example all the matches will be replaced with
a literal "$1" not the first matched section.
I know the search string is working properly because I've tried:
$lineToBeReplaced =~ s/$searchString/$1/;
And this works but then the replacement string isn't easily changeable.
I've tried a bunch of code I've found in other places including trying to
use (?{}) and eval but I can't seem to get this to work.
Thanks for any help you can provide,
-Tyson
group... none of my searches on the group turned up the answer to this.
Basically I was wondering how I can use a variable as the replacement in a
substituion.
ie. I want to do something like this:
$lineToBeReplaced =~ s/$searchString/$replaceString/;
Where $searchString and $replaceString are defined at run-time. The
$searchString seems to work fine but I can't seem to get the $replaceString
to work with backreferencing metacharacters. (eg. $1, $2 or \1, \2) Instead
if $replaceString is "$1" for example all the matches will be replaced with
a literal "$1" not the first matched section.
I know the search string is working properly because I've tried:
$lineToBeReplaced =~ s/$searchString/$1/;
And this works but then the replacement string isn't easily changeable.
I've tried a bunch of code I've found in other places including trying to
use (?{}) and eval but I can't seem to get this to work.
Thanks for any help you can provide,
-Tyson