Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

by haukex (Bishop)
on Apr 05, 2019 at 17:52 UTC ( #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 (Cardinal) 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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2021-06-24 19:47 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (132 votes). Check out past polls.