http://qs321.pair.com?node_id=1975

vroom has asked for the wisdom of the Perl Monks concerning the following question:

How do I make an array of arrays?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I make an array of arrays?
by vroom (His Eminence) on Jan 19, 2000 at 00:00 UTC
    You can typically just do:
    $a[$i][$j]=5;
    However if you want to do a foreach on one of the sets of elements it gets more complicated.
    @array=( ["Homer","Marge","Bart","Lisa","Maggie"], ["Ned","Maude","Rod","Todd"] ); foreach my $ref(@array){ print "This family consists of: "; foreach(@$ref){ print "$_ "; } print "\n"; }
Re: How do I make an array of arrays?
by blackfrier (Initiate) on Feb 02, 2000 at 17:39 UTC
    Declaring an Array Of Arrays:
    @array = ( ['red', 'white'], ['blue', 'green', 'yellow'], ['vortex', 'singularity'] ); On the fly: for $index (0..4) { push @array, [1, 1, 1, 2]; }
Re: How do I make an array of arrays?
by faaramin (Initiate) on Dec 19, 2019 at 10:27 UTC
    I have this problem too
    But this solution did not work

    Originally posted as a Categorized Answer.