push(@a,pop(@myArrofArray));A Perl 2D array is array of references to arrays. Above, you pop an array ref off of @myArrofArray and then push that array ref onto @a. So @a will contain a single element, a single scalar array reference.
print @a, I got ARRAY(0x858bd8)expected output: @a = ('x', 'y', 'z', 8,9,7);
Can anyone point out the mistake?
Consider:
To print the values of a "row" in a 2D array, you have to "dereference" the reference.my $array_ref = pop @myArrofArray; print "@$array_ref\n"; #dereference the reference push @a, @$array_ref; print "@a\n"; #now @a contains the entire row of values
PS: the "@a" and "@b" have special meanings within Perl, it is best to use x,y or something else.
Update: I got a few comments about not using @a or @b. My advice was an oversimplification. $a and $b have special meanings within Perl. It is completely allowed to use @a or %a - these do not have a special meaning. However I avoid those variables and recommend that others do the same. Leave the vars names a and b to Perl. This is to avoid any confusion. I guess you can have $a[0] which is first element of @a and that might be confused with $a which is completely different.
In reply to Re: Push array into array of arrays
by Marshall
in thread Push array into array of arrays
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |