Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Escape from backslash hell

by chipmunk (Parson)
on Dec 01, 2001 at 09:57 UTC ( #128838=note: print w/replies, xml ) Need Help??


in reply to Escape from backslash hell

all of my attempts thus far have failed to produce the desired result, all return either the original string or 11\\/29\\/2001.
I wonder if you're checking the results in the debugger... Be aware that if you examine the contents of a variable (with x, X, or V), the debugger will escape quotes and backslashes, in order to produce a valid quoted string. However, if you print the contents of a variable (with p or print), you get just the contents.

Here's an example, showing that your second attempt works, although the debugger's output might be a bit misleading:

DB<1> $_ = "2001/11/30" DB<2> s{/}{\\/}g DB<3> x $_ 0 '2001\\/11\\/30' DB<4> p $_ 2001\/11\/30 DB<5>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2020-09-29 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (146 votes). Check out past polls.

    Notices?