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

Expected behavior of \Q inside a bracketed character class?

Thread Previous | Thread Next
From:
Marco Moreno
Date:
October 15, 2014 04:30
Subject:
Expected behavior of \Q inside a bracketed character class?
Message ID:
C9867A31-BB52-40EB-B10E-A7BA88355930@pobox.com
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 Previous | 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