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 04:30
Expected behavior of \Q inside a bracketed character class?
Message ID:
Using a \Q inside a bracketed character class, should this return true or false?  This returns "false" for my 5.18.2 and 5.20.0 installs.

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

The use of \Q & \E inside a bracketed character class seems to be somewhat undefined.  It does not appear to be explained 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