in reply to How to escape single quote(s) without the use of quotemeta
I prefer to record the positions of the single quotes then use substr to escape them, working backwards from the end of the string. I tend to avoid double backslash confusion by using the \x5c ASCII literal, although in this simple case q{\\} would be fine.
use 5.026; use warnings; my $string = q{This sting it's bothering to escape ' single characters +}; my @posns; push @posns, pos $string while $string =~ m{(?=')}g; substr $string, $_, 0, qq{\x5c} for reverse @posns; say $string;
I hope this is helpful.
Cheers,
JohnGG
|
---|
In Section
Seekers of Perl Wisdom