in reply to Using an array element as a loop iterator
Not doing a very good job of reading the OP, people.
use strict; use warnings; my ($a); my @b=(2,4,6,7); foreach $a (@b) { print $a}
That works. What if I want to use one element of an array as the iterator? After all, $a[1] is really just a scalar, right?
use strict; use warnings; my @a=(1,2,3); my @b=(2,4,6,7); foreach $a[1] (@b) { print $a[1] }
Syntax error though, "near $a[". My guess is perl expects a scalar variable here, and $a[1] isn't a valid scalar variable name, even though it represents a scalar value.
|
|---|