in reply to Push array into array of arrays
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
|
|---|