Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
However, 'some\\text' and "some\\text" don't behave as you would expect

I got the following (abbreiviated) results:

Case 1 'some\text': some\text ------- PV = 0x1aa01f0 "some\\text"\0 Case 2 'some\\text: some\text ------- PV = 0x1aa01f0 "some\\text"\0 Case 3 "some\text": some ext ------- PV = 0x1aa01f0 "some\text"\0 Case 4 "some\\text": some\text ------- PV = 0x1aa01f0 "some\\text"\0

If you obtained the above, perl behaved as expected (or at least as documented). According to to the relevant docs,

double-quoted string literals are subject to backslash and variable substitution; single-quoted strings are not (except for \' and \\).

In single quotes, perl interprets the backslash literally (instead of an escape) unless followed by another backslash or by a single quote. This DWIM most of the time, since few characters ever need to be escaped in single-quoted strings. For example, '\n' results in the string {backslash}+{lowercase n}.

In double quotes, perl interprets the backslash and the following character as an escape (instead of literally). How perl interprets an invalid/unrecognized escape sequence is undocumented (or unclearly documented), but the behaviour has consistently been to replace the escape sequence with the character that followed the backslash. This DWIM most of the time, since the extra backslash was probably a case of overzealous escaping. For example, "\<" results in the string {right angle bracket}.

If you don't see the necessity of the equivalency of
"some\\text"
and
'some\\text'
try answering the following questions:

  • How would you code the string {backslash}+{backslash} using single quotes?
  • How would you code the string {backslash}+{backslash} using double quotes?
  • How would you code the string {backslash}+{backslash}+{single quote} using single quotes?
  • How would you code the string {backslash}+{backslash}+{double quote} using double quotes?
  • How would you code the string {backslash}+{single quote} using single quotes?
  • How would you code the string {backslash}+{double quote} using double quotes?

In reply to Re^7: Escaping multiple escape chars by ikegami
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 perusing the Monastery: (2)
As of 2024-04-25 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found