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

Re: perl -we '$00' dies in 5.32

Thread Previous | Thread Next
From:
book
Date:
July 25, 2022 10:11
Subject:
Re: perl -we '$00' dies in 5.32
Message ID:
Yt5sOVg+H/3ot2FV@kapow.home
On Fri, Jul 22, 2022 at 02:53:38PM +0000, Perl 5 Porters wrote:
> 
> I wonder whether it was possible to improve $10 processing whereas for the old behaviour to remain for $00 ?
> 
> I accidentally catched this error, and haven't noticed until today. I wonder how much users in the wild will catch the same error after upgrade?
> Notice that CPAN modules will unlikely use $00, however random users could use it in their scripts.
> 

However, these variables prefixed with 0 sound very fragile and
confusing to me.

(The following examples were run under perl 5.32.1.)

    $ perl -E '$0999 = 999; say $0999'
    Numeric variables with more than one digit may not start with '0' at -e line 1.

    $ perl -E '$999 = 999; say $999'
    Modification of a read-only value attempted at -e line 1.

Every single variable made of digits only is reserved for regular
expression captures, thus read-only, and not really useful as a
variable.

The only way I can imagine a program dealing such variables is via soft
references, but this still "works" in the newer Perls:

    # I was expecting this first example to fail. Maybe it should?
    $ perl -E '$name = "0999"; $$name = $name; say $$name'
    0999
    $ perl -E '$name = "999"; $$name = $name; say $$name'
    Modification of a read-only value attempted at -e line 1.

The code examples given earlier do not seem to use soft references.

-- 
 Philippe Bruhat (BooK)

 History is made by the winners and written by those with the loudest voices.
                                    (Moral from Groo The Wanderer #10 (Epic))

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