angelblade27
asked on
replace
i'm trying to substitute a string with another string but get compliation errors
my $string1="this is the way to go ${this_is} and to go there ${this_is} u must travel there. hope this helps ${this_is} ;
my $string2="bob";
$string1=~s/\$\{this_is\}/ $string2/g ;
print "$string1";
my $string1="this is the way to go ${this_is} and to go there ${this_is} u must travel there. hope this helps ${this_is} ;
my $string2="bob";
$string1=~s/\$\{this_is\}/
print "$string1";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, because $string1 is set with double-quotes, it will interpolate the variables.
So ${this_is} (which is the same as $this_is) will be interpreted right away.
If you don't want this, either escape the $, or use single quotes:
my $string1='this is the way to go ${this_is} and to go there ${this_is} u must travel there. hope this helps ${this_is}';
OR
my $string1="this is the way to go \${this_is} and to go there \${this_is} u must travel there. hope this helps ${this_is}";