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

Re: tr'''

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
July 17, 2018 08:19
Subject:
Re: tr'''
Message ID:
20180717081906.GU2750@iabyn.com
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.


-- 
Little fly, thy summer's play my thoughtless hand
has terminated with extreme prejudice.
        (with apologies to William Blake)

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