Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 chilling in the Monastery: (7)
As of 2020-05-30 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (171 votes). Check out past polls.

    Notices?