develooper Front page | perl.perl5.porters | Postings from July 2018

Re: tr'''

Thread Previous
From:
Karl Williamson
Date:
July 17, 2018 13:48
Subject:
Re: tr'''
Message ID:
814584ad-297a-7fa7-b7ef-70602201b40e@khwilliamson.com
On 07/17/2018 02:19 AM, Dave Mitchell wrote:
> On Mon, Jul 16, 2018 at 07:49:31PM -0600, Karl Williamson wrote:
>> We do not fully support tr with single quotes.  What does work is if all the
>> characters in it are ASCII and  each is listed  without using ranges.  If
>> you do use a range, instead the dash is taken literally, so
>>
>> $ blead -le "my \$foo = 'B'; \$foo =~ tr'A-Z'a-z'; print \$foo"
>> B
>>
>> $ blead -le "my \$foo = 'A'; \$foo =~ tr'A-Z'a-z'; print \$foo"
>> a
>>
>> It would be some work to fix it to work properly in general, and I'm
>> wondering if it is worth it, given that no one has ever complained, though I
>> filed https://rt.perl.org/Ticket/Display.html?id=130679 based on code
>> reading.
>>
>> Instead of fixing it, an easier option would be to detect any uses where it
>> doesn't work as expected and to raise a warning, probably a deprecation one
>> so that we can at some later point die on such uses.
>>
>> Easier still is to document that a dash is taken literally.
> 
> It's already documented in perlop:
> 
>      =head2 Gory details of parsing quoted constructs
>      ....
>      =over 4
> 
>      =item Interpolation
>      ....
>      =over 4
>      ....
> 
>      =item C<''>, C<q//>, C<tr'''>, C<y'''>, the replacement of C<s'''>
> 
>      The only interpolation is removal of C<\> from pairs of C<\\>.
>      Therefore C<"-"> in C<tr'''> and C<y'''> is treated literally
>      as a hyphen and no character range is available.

Since no one commented on ticket #130679 in a year and a half, saying 
that my premise was wrong and the ticket should be rejected, and 
certainly some people besides Tony Cook have looked at that ticket, it 
appears that this fact isn't well known, so I will create a patch to 
improve the documentation.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About