Dear Programmer of the Future (is it really 12/08/02 where you are?), If there was a global variable for the iterator in a foreach loop, what would it be when there's a loop inside a loop? And would concentric loops like that even be possible? One could argue that a feature of that iterator would be that you could decrement it and repeat the same iteration, but with a concentric loop, the inner loop would screw up the outer loop.
Anyway, to put your mind at ease, use the for(;;) syntax. The big difference is that you have to pull $_ out of the array yourself. for (my $counter=0;$counter<=$#array;$counter++) { $_=$array[$counter]; #do something print $another_array[$counter]; } , , , | Duane Bronson /|/|/| , | [EMAIL PROTECTED] ( ( ( |/| | http://www.nerdlogic.com/ \ ( | | 453 Washington St. #4A, Boston, MA 02111 | / | (617) 515-2909 ----- Original Message ----- From: "Komtanoo Pinpimai" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, December 08, 2002 11:56 PM Subject: [Boston.pm] for loop iterator variable -- !? > Hello > Sorry if it has already been listed in a perl document, however I cannot discover it, > > My curiosity is that: > > Is there the "iterator variable" for "for or foreach" loop ? > At this present, when I need access to get current index of an array when looping with for, I do this > > my $counter=0; > for (@array) { > #do something > > print $another_array[$counter]; > ++$counter; > } > > you see? It is not elegant.. has perl this iterator variable ? > > > _______________________________________________ > Boston-pm mailing list > [EMAIL PROTECTED] > http://mail.pm.org/mailman/listinfo/boston-pm > > _______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm