Re: foreach v. c-style for loop was Re: Fidning the index of an array

2002-04-12 Thread Jonathan E. Paton
> >> my @array = (1 .. 100); > >> my $counter = 0; > >> > >> for (@array) { > >> print "index -> $counter element -> $_\n"; > >> $counter++; > >> } > > > > The other approach is to use a C-style for-loop. > > Is there any given advantage of one over the other in > terms of performance and/o

foreach v. c-style for loop was Re: Fidning the index of an array

2002-04-12 Thread drieux
On Thursday, April 11, 2002, at 05:09 , Jeff 'japhy' Pinyan wrote: >> my @array = (1 .. 100); >> my $counter = 0; >> >> for (@array) { >> print "index -> $counter element -> $_\n"; >> $counter++; >> } > > The other approach is to use a C-style for-loop. Is there any given advantage of one

Re: Fidning the index of an array

2002-04-11 Thread Jeff 'japhy' Pinyan
On Apr 11, James Taylor said: >How can I get the current index of an array while processing the array >in a loop? I know I can do it with a counter type function, but I was >curious if there was a better way of doing this. That won't be automatic until Perl 6. Your method is fine. >my @array

Fidning the index of an array

2002-04-11 Thread James Taylor
How can I get the current index of an array while processing the array in a loop? I know I can do it with a counter type function, but I was curious if there was a better way of doing this. For example: my @array = (1 .. 100); my $counter = 0; for (@array) { print "index -> $counter elem