Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by haukex (Archbishop)
on Apr 05, 2019 at 17:52 UTC ( [id://1232204]=note: print w/replies, xml ) Need Help??


in reply to How to escape single quote(s) without the use of quotemeta

In my experience, with this kind of question, it helps to know exactly what format is expected. First, you said "I only need to escape the specific character '", which is easily solved by hippo's suggestion of s/'/\\'/g, but later on you said "I thought also about escaping the back slash character" - so do you want to escape both backslashes and single quotes? Are there maybe any more characters? In other words, what will you be using these strings for, what API are you passing them to? That would be a good reference for the expected format.

Replies are listed 'Best First'.
Re^2: How to escape single quote(s) without the use of quotemeta
by LanX (Saint) on Apr 05, 2019 at 18:58 UTC
    I agree, but I'm expecting it only to reflect the escaping rules inside a single quote.

    Inside single quotes it's only possible to escape another single quote and backslash.

    (This rule varies of course if you use q() with differing boundary characters.)

    Using Data::Dumper should be sufficient here, otherwise the OP should show us where it fails.

    We can't know which interface he is using, probably he's shelling out ... in this case it's most probably a XY problem.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found