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 = (1 .. 100); >my $counter = 0; > >for (@array) { > print "index -> $counter element -> $_\n"; > $counter++; >} The other approach is to use a C-style for-loop. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]