in reply to foreach count variable

I've also always wanted that feature. Sometimes you want both the element and the position at the same time.
I talked to Damian and Dan about it at the Perl conference year before last and they liked my suggestion (for Perl6) but I guess nothing ever came of it.
I proposed an attribute on the topic (list variable), ie:
foreach my $foo qw(a b c d e f g) { print $foo,$foo.index; }

Although I'm not sure that index is the best name for the attribute. Maybe position?

-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Replies are listed 'Best First'.
Re: Re: foreach count variable
by dreamy (Sexton) on Nov 19, 2002 at 08:31 UTC
    yep. in perl6 this attribute would be nice.
    there is even one more way to go:
    foreach my $foo (@bar) count $c { print $c . "-> " . $foo; }
    or maybe:
    foreach my $foo (@bar) counting $c { print $c . "-> " . $foo; }