develooper Front page | perl.perl5.porters | Postings from October 2014

Expected behavior of \Q inside a bracketed character class?

Thread Next
Marco Moreno
October 15, 2014 11:56
Expected behavior of \Q inside a bracketed character class?
Message ID:
Using a \Q inside a bracketed character class, should this return true or

perl -e 'print "foo"=~ /\Q[a-z]\E/ ? "true" : "false"'

It returns "false" for my 5.18.2 and 5.20.0 installs.

The use of \Q & \E inside a bracketed character class appears to be someone
undefined.  It does not appear to be addressed in perlre, perlreclass,
perlop, nor in perlfunc's "quotemeta".

However in perlrebackslash under "All the sequences and escapes" it states:

Those not usable within a bracketed character class (like [\da-z] ) are
marked as Not in [].
  \E                Turn off \Q, \L and \U processing.  Not in [].
  \Q                Quote (disable) pattern metacharacters till \E.  Not in

According to these docs, I would have expected \Q and \E to lose their
meaning and be ignored, thus returning true instead of false.  What is the
proper behavior?

Apologies if this is not the proper forum to address this.

Marco Moreno

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About