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

Re^2: Unrecognized escape \Q passed through in regex

by merlyn (Sage)
on Jan 27, 2006 at 03:45 UTC ( #525893=note: print w/replies, xml ) Need Help??


in reply to Re: Unrecognized escape \Q passed through in regex
in thread Unrecognized escape \Q passed through in regex

\Q and \E don't work inside interpolations. They only work in regexp literals
Fascinating theory, but easily proven wrong:
print "\Qabc*def\E\n"; # prints abc\*def
The truth is that \Q means "add backslashes to special chars until \E" in the exact same places that \n becomes a newline and $x expands to its value: every double-quoted string. A regex (that doesn't have special single-quote quoting) is just one example of that.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^3: Unrecognized escape \Q passed through in regex ('interpolations")
by tye (Sage) on Jan 27, 2006 at 04:00 UTC
    \Q and \E don't work inside interpolations. They only work in regexp literals
    Fascinating theory, but easily proven wrong:
    print "\Qabc*def­\E\n"; # prints abc\*def

    Your example shows a \Q being used inside of a quoted string, not inside of a string value being interpolated (into a string or regex). You've misunderstood how "interpolation" was originally used.

    I'll agree that the original use of "interpolation" wasn't clear enough. Though, double-quoted strings allow interpolation but I wouldn't call a quoted string that didn't contain any variables "an intepolation".

    - tye        

Re^3: Unrecognized escape \Q passed through in regex
by ikegami (Patriarch) on Jan 27, 2006 at 05:21 UTC
    I thought it worked in double-quoted literals, but my test showed otherwise. I must have made a typo in my test. In any case, that \Q works in double-quoted litarals doesn't help the OP any.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-01-28 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?