I think the canonical Perl 6 answer is:
for @array.kv -> $index, $value { do something }
Pm
On Tue, Feb 28, 2017 at 01:20:47PM -0800, ToddAndMargo wrote:
> Hi All,
>
> There are times when I want to know th4e index of an array
> when I am in a "for @array" loop. I can do it with a
> variable outside the for loop and increment it, but
> I would line to know know if there is a way to incorporate
> it in the loop command.
>
> This is my long winded way of doing it in Perl 5:
>
> while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }
>
>
> Many thanks,
> -T
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~