I have two arrays, let's call them @a1 and @a2. What I'm trying to do is obtain elements from @a2 using the values in @a1 as indices. My current attempt doesn't work properly.
foreach (@a1) {
print $a2[$_] . "at" . $_;
}
This only prints $_ but not $a2[$_].
I sense there is a trivial solution to this, but I just can't find it.
perl -E '@a1=(0,1,2); @a2=qw(a b c); for (@a1) {say $a2[$_]}'givesa,bandc..Data::Dumperto check what in a1 and a2 just before the foreach loopfor ( @a2[@a1] ) { say }