There are no multidimensional arrays in Perl. You can emulate such behavior with array of array references.
@foo = ('one','two');
@bar = ('three', 'four');
# equivalent of @baz = ('one','two','three', 'four');
@baz = (@foo, @bar);
# you need to store array references in @baz:
@baz = (\@foo, \@bar);
# Perl have a shortcut for such situations (take reference of all list elements):
# @baz = \(@foo, @bar);
# so, we have array ref as elements of @baz;
print "First element: $baz[0]\n";
print "Second element: $baz[1]\n";
# references must be dereferenced with dereferencing arrow
print "$baz[0]->[0]\n";
# -1 is a shortcut for last array element
print "$baz[1]->[-1]\n";
# but Perl knows that we can nest arrays ONLY as reference,
# so dereferencing arrow can be omitted
print "$baz[1][0]\n";
Lists are ephemeral, and exists only where they defined. You can't store list itself, but values of list can be stored, that's why lists can't be nested.
(1,2,(3,4)) is just ugly equivalent of (1,2,3,4)
But you can take a slice of a list this way:
print(
join( " ", ('garbage', 'apple', 'pear', 'garbage' )[1..2] ), "\n"
);
This syntax have no sense if @structure defined as array of scalar values:
my @structure = (@ana,@dana,@mihai,@daniel);
@{$structure[3]}[2];
You are trying to dereference string. Always use stict and warnings pragmas in your code and you will be free of such errors:
# just try to execute this code
use strict;
use warnings;
my @ana = ("Godfather", "Dirty Dancing", "Lord of the Rings", "Seven", "Titanic");
my @structure = (@ana);
print @{$structure[0]}, "\n";
Correct usage:
use strict;
use warnings;
my @ana = ("Godfather\n", "Dirty Dancing\n", "Lord of the Rings\n", "Seven\n", "Titanic\n");
my @structure = (\@ana);
# dereference array at index 0, get all it's elements
print @{$structure[0]};
print "\n";
# silly, one element slice, better use $structure[0][1];
print @{$structure[0]}[1];
print "\n";
# more sense
print @{$structure[0]}[2..3];
You can read more here:
perldoc perlref
perldoc perllol
Documentation for Perl is the best documentation I ever see, take a look and have fun!