On Mon, 9 Dec 2002, Komtanoo Pinpimai wrote:
> 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 ?
I'm not sure I follow. You can tighten that up a little & make it a bit
more Perl idiomatic with something like:
foreach $i (@array) {
# do something with $i
# then if appropriate...
print $another_array[$i];
# or, perhaps better, perhaps not, use a hash:
print $another_hash{$i};
}
But I'm not sure if this gets at what you're getting at...
--
Chris Devers [EMAIL PROTECTED]
Q: What's a light-year?
A: One-third less calories than a regular year.
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm