G'day JockoHelios,
From your original post and your replies to frozenwithjoy and LanX, you appear to be experiencing a fair amount of confusion. Perhaps this short annotated script might inject some clarity:
$ perl -Mstrict -Mwarnings -le '
use Data::Dumper;
# Declare an empty array (Note: no "splice" required)
my @records;
# Initialise the array with 2 elements
# Each element must be a scalar
# If an element is an array of values, you need an arrayref
@records = ( [ "A", 1, 2, 3 ], [ "B", 4, 5, 6 ] );
print "\$records[1][2]: ", $records[1][2];
# Push another array of values (as an arrayref)
push @records, [ "C", 7, 8, 9 ];
print "\$records[2][2]: ", $records[2][2];
# "join" creates a string (strings are scalar values)
push @records, join ",", "D", 10, 11, 12;
print "\$records[3]: ", $records[3];
# Add a hash (as a hashref - which is also a scalar value)
push @records, { E => 13, F => 14, G => 15 };
print "\$records[4]{G}: ", $records[4]{G};
# The entire data structure:
print Dumper \@records;
'
$records[1][2]: 5
$records[2][2]: 8
$records[3]: D,10,11,12
$records[4]{G}: 15
$VAR1 = [
[
'A',
1,
2,
3
],
[
'B',
4,
5,
6
],
[
'C',
7,
8,
9
],
'D,10,11,12',
{
'G' => 15,
'F' => 14,
'E' => 13
}
];
See also: splice, join, perldsc - Perl Data Structures Cookbook.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.