Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

Dereferencing an array constant #22100

Closed philiprbrenan closed 1 month ago

philiprbrenan commented 1 month ago

Given that line 3 works, would it not be reasonable to suppose that line 4 should work in the same way?

use v5.34;
$a = [1..2];
say STDERR @$a, " ", @{$a}, " ",  $a->@*, " ", @{[1..3]}, " ", [1..3]->@*; # 12 12 12 123 123                     - Line 3
say STDERR @[1..3];                                                        # Number found where operator expected - Line 4
Grinnz commented 1 month ago

The @{} syntax you demonstrated is required to dereference an expression, the only times the braces are not required are for simple variable names and scalars. This does not seem like a reasonable or useful addition to me, and you receive the error you do because it is currently parsed as the variable @[.

mauke commented 1 month ago

See also https://perldoc.perl.org/perlref#Simple-Scalar.

Leont commented 1 month ago

Philip, you keep posting these poorly thought-through ideas and we keep having to close them, this happened about two dozen times now. I hate saying this but maybe you should try doing something else because language design isn't your forte.