develooper Front page | perl.perl5.porters | Postings from March 2007

Re: [perl #42043] \U ... \Q ... \E ... \E

Thread Previous
David Landgren
March 25, 2007 08:50
Re: [perl #42043] \U ... \Q ... \E ... \E
Message ID:
Rick Delaney a écrit :
> On Mar 23 2007, Abigail wrote:
>> As far as I know, the effect of a \U, \L or \Q is cancelled by the
>> first \E encountered, and no nesting happens.
>> And as long as you use \U and \L, it works this way. However, \Q seems
>> to behave differently. \Q seems to match with a matching \E, and work
>> from the inside out.
>> I don't know what "\Q-\Q-\E-\E-" is supposed to be, both '\-\---' and
>> '\-\\Q\---' have some logic (although the former would be my favourite);
>> however, currently "\Q-\Q-\E-\E-" equals '\-\\\-\--', which seems plain
>> wrong to me.
> I think this is all covered in L<perlop/"Gory details of parsing quoted
> constructs">.  Basically, everything after \Q is double-quote
> interpolated before escaping, which includes interpolating \Q sequences.
> So these are all equivalent:
>     print "\Q-\Q-\E-\E";
>     print quotemeta("-\Q-\E-\E");
>     print quotemeta("-" . "\Q-\E-\E");
>     print quotemeta("-" . quotemeta("-\E") . "-\E");

I think the only real bug in all this is

% perl -le "print qq{\Un\lext}"

According to the docs, that should print "NeXT". I cam see where and why 
in the parser it comes out like this, but at this late stage of the game 
I think it would be better to amend to documentation to say that \l and 
\u are ignored if a \U or \L are in force.

There's a bug (#9360) open on this issue.


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