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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have attempted to explain my question with 2 examples using 'some\text' and "some\text" both of which get stored as I understood they should. However, 'some\\text' and "some\\text" don't behave as you would expect and are NOT stored with the same rules as the first case because in the first case, the compiler sees the single quotes and stores the characters correctly by pushing an additional '\' to the PV array as it should. What is going wrong, however, is the case when it sees a second '\' in the literal case, and doesn't push another '\' onto the PV.
use Devel::Peek; # literal case - PV's are the same $txt = 'some\text'; print "Case 1 'some\\text': $txt\n-------\n"; # PV gets an extra '\' pushed on it. Dump($txt); $txt = 'some\\text'; print "\nCase 2 'some\\\\text: $txt\n-------\n"; #PV does NOT get an extra '\' pushed on to it Dump($txt); # quoted case - PV's handle '\' as expected $txt = "some\text"; print "\nCase 3 \"some\\text\": $txt\n-------\n"; Dump($txt); # $txt = "some\\text"; print "\nCase 4 \"some\\\\text\": $txt\n-------\n"; Dump($txt);
If you actually try these examples, then you can see for yourself how the scalars are getting stored.

Nuff said. I will ask the perl porters from here.

In reply to Re^6: Escaping multiple escape chars by JamesNC
in thread Escaping multiple escape chars by JamesNC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found