in reply to What do I do wrong? I want an array of arrays
To answer the subject - you have a number of syntactical and semantic errors here.
First, you probably want () rather than {} on the @c and @d initialisation lines:
This will create a list rather than a reference to a hash.my @c = ( 22, 44, 55 ); my @d = ( 'yy', 'tt' ); # or my @d = qw(yy tt);
Second, your assignments - an array, such as @b, can only hold scalars - not other arrays. That said, a reference to an array is a scalar. Thus, you probably want:
However, once you do that, you need to dereference it when you want to copy it into @e.$b[0] = \@c; # hold a reference to @c. $b[1] = \@d;
What you have right now creates arrays @c and @d, both of which contain a single element: a reference to a hash (again, a reference is a scalar of some type, thus can be in an array). Then you assign the "scalar" value of the array into $b[1] - the scalar value of an array is the length of the array (in this case, there's only one value in the array - the reference to the hash), and from there, you copy that 1 to @e as a single element.my @e = @{$b[1]};
Hope that helps.
|
|---|