I'm working on a Perl Dancer2 webapp and stumbled across the situation that I have an array that contains arrays that contain an array in position 2. I pass a reference to that array to a sub and then iterate over the array (that contains arrays).
When I try to get the innermost array inside a foreach() loop with @$$_[2], I get an error:
Not a SCALAR reference
I can easily work around this with:
my $ref = $$_[2];
print "@$ref\n";
but I wonder why the first approach doesn't work.
Have a look at my minimal example:
my @x = (["a", "b", [1, 2], "c"],
["x", "y", [8, 9], "z"]);
my $y = \@x;
foreach (@$y) {
# print "@$$_[2]\n"; #produces error
my $z = $$_[2];
print "@$z\n"; #works
}
Any ideas what is going on here?
$_->[2]syntax.$$_[2]more or less confusing than$_->[2]but rather a matter of habit