In Perl, arrays cannot contain other arrays. To make a multi-dimensional data structure, you need references.
Consider this example.
use strict; use warnings;
use Data::Dumper;
my @inner = qw(a b c);
my @outer = (
\@inner, # reference to existing array
[100, 200, 300], # new anonymous array reference
);
print Dumper \@outer;
This prints
$VAR1 = [
[
'a',
'b',
'c'
],
[
100,
200,
300
]
];
Your outer array is just that, an array. But the elements inside it are references to arrays. You can either reference an existing array, or create a new, anonymous one.
When dumping out the structure for debugging, note how Dumper from Data::Dumper requires a reference too, so we use the same notation with the \.
Now to add an element to @inner via its position inside @outer, you need to take the first element out @outer. To do that, the sigil changes, so you get $outer[0]. To pass that to push, we need to turn it into an array. That's called dereferencing as an array.
push @{ $outer[0] }, 'd';
When we Dumper it again, we get
$VAR1 = [
[
'a',
'b',
'c',
'd'
],
[
100,
200,
300
]
];
Because the first element is a reference to a named array variable, we can also operate on it directly.
push @inner, 'e';
This will change the value of the first element in @outer, because both refer (see why it's called a reference?) to the same thing in memory.
$VAR1 = [
[
'a',
'b',
'c',
'd',
'e'
],
[
100,
200,
300
]
];
We can't do that with the second element, because it started out as an anonymous reference.
Let's have a look at your warning.
Experimental push on scalar is now forbidden at perlscript.pl line 30, near "$element)"
In Perl 5.20.0 push on references was deprecated because it didn't work as intended, and started warning. In Perl 5.30.0 this was changed and it is now a fatal error, making your program die.
Also see perlref and perlreftut.
push(@X,$element);$elementin the inner array-reference which is located at index 0 of@X