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

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

Thread Previous | Thread Next
July 24, 2022 10:24
Re: perl -we '$00' dies in 5.32
Message ID:
On 24/07/2022 10:38, Konovalov, Vadim via perl5-porters wrote:
>> While fixing `${10}` to mean `$10` might
>> be possible it would still cause surprise and (incorrect results) for things
>> like:
>>     $010 = "foo";
>>     print ${010};  # wrong, '010' is/was parsed as octal meaning it maps
>>     to $8 and not the (probably) expected $010
> Obviously you're thinking of $00, $010, etc as result holders after regexp match.
I am not thinking about regexp match at all.
> However $0 does not have any relation to regular expression.
> And $00 name was used by me as global variable which is a "variation" of $0.
> like $i and $i0.
What I am/was trying to point out is that while you can(/could) create a
`$010` as variable there is no way to access that same variable using
the `${}` construct while being strict-safe.

With 'regular' variables you can do:

    use strict;
    my $bar = "foo";
    print ${bar}; # prints "foo"

With variables such as '$00', '$010', ... you can not do the same, i.e.:

    use strict;
    $010 = "foo";
    print ${010};  # will *not* print "foo"

Basically with the ${} construct there is nothing(*) you can use that
will get you the value of '$010' (i.e. "foo") and is strict-safe.
The reason why is because the inside of ${} is treated as an expression.
Which means in something like: `${010}` the `010` gets treated as an
expression which gets parsed as an octal which (eventually) makes(/made)
it `${"8"}`
You could use `${"010"}` but that does not work under `use strict "refs"`.

TLDR: Using variables such as $00, $010, ... is confusing since you
can't use ${00}, ${010}, ... to get it's value.
Is that confusion enough to forbid it? That's not my call..

Best regards,


(*) Okay, that's not entirely true; you can use a scalar reference to
$010; that is: ${\$010}.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About