Having a bit of a guess here but could it be that you need to push the array rather than a reference to the array? The following might illustrate the difference. Note that after the first push @AoA has three elements, the last of which is a reference to @newArr, but there are five after I pop off the array reference and do the second push of the array rather than a reference to it, the last three being the same values as are in @newArr.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MData::Dumper -E + ' my @AoA = ( [ 1, 2, 3 ], [ qw{ a b c } ], ); say Data::Dumper->Dumpxs( [ \ @AoA ], [ qw{ *AoA } ] ); my @newArr = qw{ x y z }; push @AoA, \ @newArr; say Data::Dumper->Dumpxs( [ \ @AoA ], [ qw{ *AoA } ] ); say $AoA[ -1 ]; say qq{@{ $AoA[ -1 ] }}; pop @AoA; push @AoA, @newArr; say Data::Dumper->Dumpxs( [ \ @AoA ], [ qw{ *AoA } ] );' @AoA = ( [ 1, 2, 3 ], [ 'a', 'b', 'c' ] ); @AoA = ( [ 1, 2, 3 ], [ 'a', 'b', 'c' ], [ 'x', 'y', 'z' ] ); ARRAY(0x555eb3457760) x y z @AoA = ( [ 1, 2, 3 ], [ 'a', 'b', 'c' ], 'x', 'y', 'z' );

I hope this is helpful.

Update: Expanded explanation.

Cheers,

JohnGG


In reply to Re: Push array into array of arrays by johngg
in thread Push array into array of arrays by Anonymous Monk

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.