[Chicago-talk] Arrays of array references

Clyde Forrester clydeforrester at gmail.com
Fri Nov 4 20:03:27 PDT 2011

I've decided that I want to do something which involves having an array 
of arrays. Technically, I can't. Array elements must be scalar, but that 
scalar can be a reference to an array. OK, whatever. I'm thinking in 
terms of an array of (pointers to) objects.

So now I'm trying to wrap my brain around the syntax.

If I declare an array of references like this:

@mess = ( [ "foo" , "bar" ],
           [ "baz" , "quux" ], );
push @mess, [ "fred" , "wilma" ];

Then I can get the size of the array, or one element like this:

print @mess."\n"; # 3, the size of the mess array
print $mess[2][1]."\n"; # wilma, the second element of the array pointed
                         # to by the third element of the mess array

But I would like to know how to print the contents of the array to which 
the third element points. Something which would print:

fred wilma

And I'm quite unsure how I would properly do a shift or pop which would 
give me the array to which one element points.

I've tried a number of forms which either give me an array pointer, a 
blank stare, or an error. But not a scalar or group of scalars. I have 
seen foreach constructs which will dump everything, but I'm not trying 
to dump everything, just extract or print or otherwise fiddle with one 

And, of course, perhaps I'm approaching the problem entirely wrong.

I looked at Perl 101. Apparently I am researching the page on arrays of 
arrays. :-)

Can anyone at least point me in the right direction?


More information about the Chicago-talk mailing list