Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to escape single quote(s) without the use of quotemeta

by johngg (Canon)
on Apr 05, 2019 at 16:34 UTC ( #1232201=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1232201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2021-06-23 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (115 votes). Check out past polls.

    Notices?