gurpreetsingh13 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks.
I think this is a simple question. But somehow not working for me.
Can we use an array element as a loop iterator for another array?
Here is the code which fails(Ignoring all strict and other things).
perl -e '@a=(1,2,3);@b=(2,4,6,7);foreach $a[1](@b){print $a[1];}'
Error: syntax error at -e line 1, near "$a["
I have checked. This works with a c-style for loop.
for($a[1]=0;$a[1]<3;$a[1]++){print $b[$a[1]];}
Similar thing works in python. What is the mistake in this due to which it is failing. Would be thankful for your help
Back to
Seekers of Perl Wisdom