On 16 Aug 2000, Perl6 RFC Librarian wrote:
> This and other RFCs are available on the web at
> http://dev.perl.org/rfc/
>
> =head1 TITLE
>
> Implicit counter in C<for> statements, possibly C<$#>.
>
> =head1 VERSION
>
> Maintainer: John McNamara <[EMAIL PROTECTED]>
> Date: 16 Aug 2000
> Version: 1
> Mailing List: [EMAIL PROTECTED]
> Number: 120
>
> However, the latter format is often more convenient if you need to keep track of the
>array index as well as iterating over the array:
>
> for ($i = 0; $i <= $#array; $i++) {
> print $array[$i], " is at index ", $i, "\n";
> }
>
> is more succinct than:
>
> $i = 0;
> foreach $item (@array) {
> print $item, " is at index ", $i, "\n";
> $i++;
> }
>
What about:
for (0..$#array) {
print $array[$i], " is at index ", $i, "\n";
}
I use that whenever I need to loop over indices of two arrays at once.
--
Tim Jenness
JCMT software engineer/Support scientist
http://www.jach.hawaii.edu/~timj