The thing is, I think for (@array) is optimized to take a reference to the array rather putting it in list context (similarly to how for (x..y) is optimized not to flatten the list).
sub f4 {
for (@_) {
print($_);
shift;
}
print("\n");
}
sub f5 {
for ((), @_) {
print($_);
shift;
}
print("\n");
}
f4(map/./g, Japh); # Jp
f5(map/./g, Japh); # Japh
(Copied from Re^3: For vs. While)
I believe there are 5 kinds of for loops.
- for (x; y; z) (C-style syntax)
- for (x..y) (Not flattened)
- for (ARRAY) (Not flattened)
- for (reverse LIST) (Flattened, but no explicit call to reverse)
- for (LIST)
|