Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I make an array of arrays?

by vroom (His Eminence)
on Jan 12, 2000 at 00:07 UTC ( [id://1975]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found