Andrew Gaffney wrote:
Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrote: : : I have code that uses a 'foreach(@array) {}' to loop : through an array. I now need to be able to get the : array index inside of that. I know I could switch to : a 'for($loopvar=0;$loopvar<@array;$loopvar++) {}' to : do that, but I'd have to change some other code also. : If not that way, is there a way to get the array : index inside of a loop like 'for(0..$#array) {}'?
You could count the index: { my $index = 0; foreach my $value ( @array ) { . . . $index++; } }
The outer braces keep $index to a smaller scope. BTW, $value above is an alias. If you are needing the index to change the current value in @array you can do it by changing $value.
I figured that's what it would probably come down to. I don't need the index for something in the array I'm working with but to access a related array with related data at the same indexes.
Would hashes be usefull for you there?
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>