Regular iteration with incremented tracker:foreach my $i (0..$#array) { print "$i: $array[$i]\n"; }
Old-school C-style method:my $i = 0; foreach my $e (@array) { print "$i: $e\n"; $i++; }
In this case, I'd say the first is "better" since it requires less code.for (my $i = 0; $i < @array; $i++) { print "$i: $e\n"; }
In reply to Re: find the element position of $scalar
by tadman
in thread find the element position of $scalar
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |