Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by LanX (Cardinal)
on Apr 05, 2019 at 14:57 UTC ( #1232196=note: print w/replies, xml ) Need Help??


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

not sure if I understand your requirement, does q help?

DB<2> x q(LanX' solution) 0 'LanX\' solution' DB<3> x q(LanX\' solution) 0 'LanX\\\' solution'

edit

DB<14> use Data::Dump qw/dd/ DB<15> dd q(LanX' solution) "LanX' solution" DB<16> dd q(LanX\' solution) "LanX\\' solution"

If not what is your desired output?

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

Replies are listed 'Best First'.
Re^2: How to escape single quote(s) without the use of quotemeta
by thanos1983 (Parson) on Apr 05, 2019 at 15:23 UTC

    Hello LanX,

    I have also tried with q but it did not worked for me.

    The desired output would be something like:

    #!/usr/bin/perl use strict; use warnings; use feature 'say'; my $string = "It's"; say quotemeta $string; __END__ $ perl test.pl It\'s

    Thanks again for your time and effort.

    BR / Thanos

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      what about the backslash, do you really want quotemetas behavior?

      DB<26> x q(It's\ ) 0 'It\'s\\ ' DB<27> x quotemeta q(It's\ ) 0 'It\\\'s\\\\\\ ' ... DB<29> x quotemeta q(It's\x) 0 'It\\\'s\\\\x'

      FWIW you can write a regex which consumes every paired backslash in an or'ed condition before replacing single quotes/backslashes.

      But a real test-cases are imperative here.

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

      update

      this shows that the input format should be well defined too

      DB<37> dd quotemeta q(It's\x\\) "It\\'s\\\\x\\\\"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2021-06-16 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (75 votes). Check out past polls.

    Notices?