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.

-- Ken


In reply to Re: element of an array of arrays by kcott
in thread element of an array of arrays by JockoHelios

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.