in reply to Complex Data Structures in Object Creation

Oh yee of little sanity, check ye pod before you falleth from grace.. ;-^)

Check out perlref or perlreftut for help on creating references and 2d arrays. And there's always the Categorized Questions and Answers section.

to make a two dimensional array (an array of arrays), do something like:

my @array = (1,2,3); my @2darray = (\@array, \@array, \@array); #or my @3darray = ( [ [11,12,13], [21,22,23], [31,32,33] ] ); print $3darray[0][3][3]; # yields 33
update: Actually print $3darray[0][2][2]; # yields 33. Just keepin' you on yer toes, zort Masem.

update:
Disregard what Zaxo said.

You don't lose the anonymous hash since it is being returned implicitly (because it is the last statement in sub, and bless returns the reference being blessed).

However, I do like to return things explicitly, as you never know what'll happen in perl 6 (doesn't really matter if you don't use it, but its good to be as explicit as possible).

Basically, what I would do is:

package foo; sub new { my ($class) = shift; my $self = {}; # a ref to an anon hash $self->{some_scalar} = "blah"; $self->{an_array_of_arrays} = [ [01,02], [11,12], [21,22]]; bless ( $self , $class ); return $self; } #so when you do my $new_object = new foo; my $array_ref = $new_object->{an_array_of_arrays}; print $array_ref->[1][1];

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"