in reply to What do \Q and \E mean?

What's between \Q and \E is treated as normal characters, not regexp characters. For example,

'.' =~ /./; # match 'a' =~ /./; # match '.' =~ /\Q.\E/; # match 'a' =~ /\Q.\E/; # no match

It doesn't stop variables from being interpolated.

$search = '.'; '.' =~ /$search/; # match 'a' =~ /$search/; # match '.' =~ /\Q$search\E/; # match 'a' =~ /\Q$search\E/; # no match

By the way, I think you want
"s{\\Q\$in\\E}{\$out}g"
instead of
"s{\\Q$in\\E}{$out}g"
The difference will be seen when $in or $out contains a '$'.

Replies are listed 'Best First'.
Re^2: What do \Q and \E mean?
by apt_get (Acolyte) on Jun 19, 2005 at 03:17 UTC
    Thanks for your nice explanation, ikegami.
    By the way, I think you want "s{\\Q\$in\\E}{\$out}g" instead of "s{\\Q$in\\E}{$out}g" The difference will be seen when $in or $out contains a '$'.

    Yes, it is evident from your explanation that that would be the case. I did not post the rest of the code, but my $in and $out are a finite set of strings, neither containing a '$'.
Re^2: What do \Q and \E mean?
by apt_get (Acolyte) on Jun 19, 2005 at 02:57 UTC
    Thanks guys, for your lightning fast responses. I thought I had it figured out in a few minutes, and by the time I updated my entry, I see three replies!! Way cool. Can you tell me how you keep track of who posts new questions, that enables you to respond so quickly... Thanks again. PM rocks. :)
      I just happened to check Perl Monks for the first time tonight at the right time. We also reload Perl Monks a fair bit, but there's no notification system (except for replies to your own posts).
      I tend to watch [id://Newest Nodes] and look at the top of the list. Even doing this, I often see replies in only minutes after a post. You might also find [id://Recently Active Threads].