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

Expected behavior of \Q inside a bracketed character class?

Thread Next
From:
Marco Moreno
Date:
October 15, 2014 11:56
Subject:
Expected behavior of \Q inside a bracketed character class?
Message ID:
CAJfRpHqvKXkOC+NyiW+ka6zDYGTod4bZC_yqSDiby=SHDR6coQ@mail.gmail.com
Using a \Q inside a bracketed character class, should this return true or
false?

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About