[Israel.pm] negative array indexing

Yuval Yaari yuval at windax.com
Sun Feb 15 04:40:26 PST 2004


I wanted to try it and this is what I got:
 > perl -MData::Dumper -le 'my @a=(1,2,3); $a[-5]=4; print Dumper(\@a)'
Modification of non-creatable array value attempted, subscript -5 at -e 
line 1.

As for the first question:
 > perl -MData::Dumper -le 'my @a=(1,2,3); @a[3]=4; print Dumper(\@a)'
$VAR1 = [
          1,
          2,
          3,
          4
        ];

So Perl isn't strict about it.
When turning on warning it warns me:
Scalar value @a[3] better written as $a[3] at -e line 1.

  --Yuval




More information about the Perl mailing list