http://qs321.pair.com?node_id=525893


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.