develooper Front page | perl.perl5.porters | Postings from December 2011

Re: What's the difference between qr/\U\x{39}/ and qr/\U\x{3a}/ ?

Thread Previous | Thread Next
From:
Karl Williamson
Date:
December 3, 2011 14:26
Subject:
Re: What's the difference between qr/\U\x{39}/ and qr/\U\x{3a}/ ?
Message ID:
4EDAA206.9020200@khwilliamson.com
On 11/29/2011 04:49 AM, Nicholas Clark wrote:
> On Thu, Nov 24, 2011 at 01:24:33PM -0500, Eric Brine wrote:
>> On Thu, Nov 10, 2011 at 12:36 AM, Karl Williamson
>> <public@khwilliamson.com>wrote:
>>
>>> I would not have expected either of these outcomes.  How many of you got
>>> it right?
>>>
>>
>> It's quite well established that \x{39} in double-quoted literals is 9.
>>
>>> perl -E"say qq/\U\x{39}/"
>> 9
>>
>> qr is a form of double-quoted string literal, but it behaves differently.
>>
>>> perl -E"say qr/\U\x{39}/"
>> (?^u:\X{39})
>>
>> While I understand why qr works the way it does, I don't see any reason for
>> qr to behave differently. qr/...\x{39}.../ should produce 9 or equivalent.
>> I say equivalent, since it would be ideal to keep the original pattern
>> (\x{39}) in order to avoid unescaping meta chars, and to avoid introducing
>> unprintable or hard to print characters in regex stringifications.
>
> I think I now know why. I found the explanation in the documentation:
>
> perlop.pod says:
>
>      For the pattern of regex operators (C<qr//>, C<m//>  and C<s///>),
>      the quoting from C<\Q>  is applied after interpolation is processed,
>      but before escapes are processed. This allows the pattern to match
>      literally (except for C<$>  and C<@>). For example, the following matches:
>
>          '\s\t' =~ /\Q\s\t/
>
> By design \Q quotes the pattern that follows, so requires this ordering.
> \U, \u, \L and \l are implemented at the same point as \Q
>
> Nicholas Clark
>

I think that \Q does the right thing, but I don't think that this should 
mean that \U, etc have to do that exact same thing.  I'm unclear as to 
whether you are saying that they should do what \Q does, or whether your 
saying the reason they do so is an accident (and oversight) of 
implementation, and that you would not object to changing their behavior 
within the scope of a use '5.016'

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