On 5/21/05, Peter Rabbitson wrote: > Hello, > > When perl executes a foreach loop, it creates some kind of array of all the > iterators
I'm assuming you mean that this code: foreach my $num (1..1_000_000) { do_something($num); } creates a one-million number array? No, it doesn't, at least not in current versions of Perl. Quoting "perldoc perlop": "In the current implementation, no temporary array is created when the range operator is used as the expression in foreach loops". > and then goes over them one by one. Is the current index pointer > accessible from inside the loop? I was unable to find anything related in > perlvar. > Neither was I, but I suspect the reason is that if you need a counter, you should not be using "foreach". Instead, use "for": for(my $counter = 0; $counter < @array; ++$counter) { do_something_with($array[$counter]); } HTH, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>