- or download this
sub getArrayIndex {
my $value = shift;
...
}
return -1;
}
- or download this
for ($i=0,$i<$x,$i++)
- or download this
# to just iterate over an array; each element assigned to $_
# changing $_ changes the original array element
...
for $i(0..10) {
# $i will be set to 0 to 10 in sequence
}
- or download this
for (0..$#array) { }
for (0..@array) { }
- or download this
@array = qw(1);
print "My array @array\n";
...
for (0..@array) {$array[$_]++}
}
print "My array @array\n";
- or download this
My array 1
My array 12 11 10 9 8 7 6 5 4 3 2 1
- or download this
# really short idiomatic version
...
@array = qw(0 2 4 6 8 10 12);
print getArrayIndex(6,@array),"\n";
print getArrayIndex(5,@array),"\n";