As an historical aside, note that using the result of evaluating the expression (scalar @ra) - 1 is not quite the same as using an index of -1 or $#array if you have set the array base $[ (which defaults to 0) to be 1 — but don't do that! See $[ in Deprecated and removed variables in perlvar. Assignment to $[ was first deprecated in Perl version 5.12 and has been increasingly constrained in subsequent versions.
In all cases (and regardless of the array base — but again, don't futz with that):c:\@Work\Perl\monks>perl -wMstrict -le "$[ = 1; ;; my @ra = qw(zero one two three); ;; print scalar @ra; print 0 + @ra; print $ra[ (scalar @ra) - 1 ]; print $ra[ @ra - 1 ]; print $ra[ @ra ]; print $ra[ -1 ]; print $ra[ $#ra ]; " Use of assignment to $[ is deprecated at -e line 1. 4 4 two two three three three
Give a man a fish: <%-{-{-{-<
In reply to Re: What array negative number counting means
by AnomalousMonk
in thread What array negative number counting means
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |