in reply to Re^2: how internally $#array is working in Perl
in thread how internally $#array is working in Perl

I suspect you can assign 1 to it, but other values are silently ignored

You suspect incorrectly.

$ perl -e '@array=(qw(ant bat cat)); $[ = 94; print $array[95]."\n"' bat $ perl -e '@array=(qw(ant bat cat)); $[ = -9; print $array[-8]."\n"' bat

Replies are listed 'Best First'.
Re^4: how internally $#array is working in Perl
by ikegami (Patriarch) on Aug 13, 2010 at 13:53 UTC

    You're not even limited to positive numbers.

    $ perl -wle'$[ = -3; $_ = "abcdef"; print substr($_,0,1)' Use of assignment to $[ is deprecated at -e line 1. d

    You could get weird constructs that caused Perl to crash:

    $ perl -we'$[ = 3; $_ = "abc"; my $x = substr($_,2,1)' panic: sv_setpvn called with negative strlen at -e line 1.

    I fixed it in 5.10.1 or 5.12.0 when fixing another bug:

    $ perl -we'$[ = 3; $_ = "abc"; my $x = substr($_,2,1)' Use of assignment to $[ is deprecated at -e line 1. substr outside of string at -e line 1.

    Keep in mind $[ is slated to be removed from Perl.

      You're not even limited to positive numbers.
      yes, as I demonstrated with my example that used -9 :-)
      Keep in mind $[ is slated to be removed from Perl.
      has a2p been considered when making this change?