Link to home
Start Free TrialLog in
Avatar of angelblade27
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";
Avatar of Adam314
Adam314

The $string1 doesn't have a closing quote
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}";

ASKER CERTIFIED SOLUTION
Avatar of tone28
tone28

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial