replacing this backlash (\) with no backlash

D

Devop

hi.

I have been replacing string with backslas (\) with an other without
backlash.

This is part of the code
The reason i use \ in front of $ is that , $ is included in my search.

But when i replaced with the second variable, i get \${string2} - i
love you & (see the backlash is with me again ? how can i ignore this
backlash? . I want to get just {string2} - i love you &

my $first = '\${string1} &';
my $second = '\${string2} - i love you &';


$change =~ s/$first/$second/ms;


rgds
 
B

Beable van Polasm

Devop said:
I have been replacing string with backslas (\) with an other without
backlash.

This is part of the code
The reason i use \ in front of $ is that , $ is included in my search.

But when i replaced with the second variable, i get \${string2} - i
love you & (see the backlash is with me again ? how can i ignore this
backlash? . I want to get just {string2} - i love you &

my $first = '\${string1} &';
my $second = '\${string2} - i love you &';

I'm not sure I understand the problem. Would this work?

my $second = '{string2} - i love you &';
$change =~ s/$first/$second/ms;


--
 
D

Devop

The problem is i need the $ sign in the search and i have to use \ so that $
will not have a value

But how can i ignore \ in the substitution operation ?

rgds
 
A

Anno Siegel

Devop said:
-=-=-=-=-=-

hi.

I have been replacing string with backslas (\) with an other without
backlash.

This is part of the code
The reason i use \ in front of $ is that , $ is included in my search.

But when i replaced with the second variable, i get \${string2} - i
love you & (see the backlash is with me again ? how can i ignore this
backlash? . I want to get just {string2} - i love you &

my $first = '\${string1} &';
^
That backslash has no function in single quotes, it is included literally
in your string. Print out "$first" before the substitution to see it.
my $second = '\${string2} - i love you &';

Since your substitution does nothing about a literal backslash, it stays in.
You don't want to "ignore" the backslash, you don't want to put it in the
original string in the first place.

my $first ='${string1} &';

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top