There might be an extra op in the @x-1 version, but using the latter because of this would be "premature optimization". Pick whichever one you prefer. Personally, I prefer beating around the bush and use last ($#x) if I mean last, and count (@x) if I mean count. The down side is that the reader must be familiar with both ops.
But that's assuming (deprecated) $[ is left untouched.. If $[ is 1, they're both wrong. The solution for $[ = 1 is
for my $y (1..$#x) { }
or
for my $y (1..@x) { }
and the general solution is
for my $y ($[..$#x) { }
or
for my $y ($[..$[+@x-1) { }
In reply to Re: (digression) preferred syntax for index of last array element?
by ikegami
in thread Initialization of arrays
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |