Consider this:
my $var = "${SOME_VAR}"
my $string "In this text ${SOME_VAR} will be replaced with X"
$string =~ s/$var/X/g;
print "\nprocessed string = <".$string.">";
returns
processed string = <In this text ${SOME_VAR} will be replaced with X>
i.e. the replace does not take place.
However, if $var does not contain a reserved character ($), the replace DOES take place:
my $var = "SOME_VAR"
/* everything else the same */
returns
processed string = <In this text ${X} will be replaced with X>
But I do not know how to escape reserved characters when they are contained within a variable, i.e. when the search token is not explicit but parametarized.
Any idea?
Thanks
Your string contains
$which has a special meaning.. You can use\Qand\Eto get it work..\Q disables pattern metacharacters until \E