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) {}'?
I've used your last suggestion many times:
for(0..$#array) { print "Number $_ is $array[$_]\n"; }
or to keep the value in $_ (and a *little* extra work):
my $ix = 0; for(@array) { print "Number $ix is $_\n"; $ix++; }
HTH
Lee.M - JupiterHost.Net
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>