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

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

Thread Previous | Thread Next
From:
Rick Delaney
Date:
March 24, 2007 07:00
Subject:
Re: [perl #42043] \U ... \Q ... \E ... \E
Message ID:
20070324140008.GD4492@bort.ca
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");

-- 
Rick Delaney
rick@bort.ca

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