P
Peng Yu
Hi,
I know at least three ways to iterator an array. But I'm not sure if
the first two iteration methods would iterator the array in order
(from the first element to the last element). Can somebody let me
know?
What is the best way to iterator an array?
Thanks,
Peng
#!/usr/bin/perl
@array = (1, 2, 3, 4);
foreach(@array) {
print "$_\n";
}
for my $elem (@array) {
print "$elem\n";
}
for($i = 0; $i <= $#array; ++ $i) {
print "$array[$i]\n";
}
I know at least three ways to iterator an array. But I'm not sure if
the first two iteration methods would iterator the array in order
(from the first element to the last element). Can somebody let me
know?
What is the best way to iterator an array?
Thanks,
Peng
#!/usr/bin/perl
@array = (1, 2, 3, 4);
foreach(@array) {
print "$_\n";
}
for my $elem (@array) {
print "$elem\n";
}
for($i = 0; $i <= $#array; ++ $i) {
print "$array[$i]\n";
}