Perl / perl5

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

__ARRAY__ like __SUB__ #22105

Closed philiprbrenan closed 1 month ago

philiprbrenan commented 1 month ago

Currently we have the very useful __SUB__ constant which points to the current sub. Might it not be also helpful to have an __ARRAY__ constant which would point to the current array as shown in the last line below:

use v5.34;
use warnings FATAL => qw(all);

my @i  = 1..10;
say STDERR @i[0..$#i/2];         # 12345 
say STDERR @i[0..$#__ARRAY__/2]; # Global symbol "@__ARRAY__" requires explicit package name
mauke commented 1 month ago

That last line doesn't use an __ARRAY__ constant, it uses an array called @__ARRAY__ (hence the error message).