I have two data structures in Perl:
An array:
my @array2 = ( \"1\", \"2\", \"3\");
for $elem (@array2) {
print $elem.\"\\n\";
}
<
The square brackets create an anonymous array, populate the array with the contents of the brackets, and return a reference to that array. In other words,
[ "1", "2", "3" ]
is basically the same as
do { my @anon = ("1", "2", "3"); \@anon }
So the code should look like
my $array_ref = [ "1", "2", "3" ];
for (@$array_ref) { # Short for @{ $array_ref }
print "$_\n";
}
or
my @array_of_refs = ([ "1", "2", "3" ]);
for my $array_ref (@array_of_refs) {
for (@$array_ref) {
print "$_\n";
}
}