That prints all four elements of b
and then a contains : [1, 13, 3]. So it does not correspond to your C-style for loop where you only print the first three elements, and the second value in the declaration of a is just thrown away.10 11 12 13
To achieve the same result in Perl you can do:
@a = 1..3; @b = qw/2 4 7 9/; for (@b) {$a[1] = $_; say; }
In reply to Re^3: Using an array element as a loop iterator
by Eily
in thread Using an array element as a loop iterator
by gurpreetsingh13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |