in reply to Re^2: How to substitute a string containing "\" with same string in quotes.
in thread How to substitute a string containing "\" with same string in quotes.
Hi
Check the input itself is not containing the '\', because it is interpolated in double quotes.
use strict; my $string = "this is my sting with \ and /slashes. put substing in qu +otes"; my $substring = "with \ and /slashes"; print $string; $string =~ s/\Q$substring\E/\"$substring\"/gi; OUTPUT: this is my sting with and /slashes. put substing in quotes
Instead use single quote in the input like,
use strict; my $string = 'this is my sting with \ and /slashes. put substing in qu +otes'; my $substring = 'with \ and /slashes'; print $string; $string =~ s/\Q$substring\E/\"$substring\"/gi; OUTPUT: this is my sting with \ and /slashes. put substing in quotes
This will give the correct output
Punitha
|
---|
In Section
Seekers of Perl Wisdom