in reply to find the element position of $scalar
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"; }
|
|---|