- or download this
my @array = qw(red blue green yellow black white purple brown orange g
+ray);
foreach (@array) {
do_something_with($_);
}
- or download this
# Inputs: $1 ... color name
# $2 ... The color index (a new arg)
...
# For now, just print the color prefixed with its index...
printf " %2d. '$color'\n", $idx;
}
- or download this
for (my $i = 0; $i < @array; $i++) {
my $item = $array[$i];
do_something_with($item, $i);
}
- or download this
my $i;
foreach (@array) {
do_something_with($item, $i++);
}
- or download this
use feature ":5.10";
my @array = qw(red blue green yellow black white purple brown orange g
+ray);
...
# 7. 'brown'
# 8. 'orange'
# 9. 'gray'
- or download this
for (@array) {
do_something_with($_, ++ state $i);
...
# 8. 'brown'
# 9. 'orange'
# 10. 'gray'
- or download this
map { do_something_with($_, state $i++) } @array;