multidimensional Array

T

Tristan

how to put more arrays in one?

@array1 = qw(Quarter Dime Nickel Penny);
@array2 = qw(test1 test2 test3 test4);
@array3 = (1,2,3,4,5,6,7,8,9,10);
@array4 = (11,22,33,44,55);


I want to have only one multidimensional array. How to do it?

Thanks.
 
A

A. Sinan Unur

Tristan said:
how to put more arrays in one?

@array1 = qw(Quarter Dime Nickel Penny);
@array2 = qw(test1 test2 test3 test4);
@array3 = (1,2,3,4,5,6,7,8,9,10);
@array4 = (11,22,33,44,55);


I want to have only one multidimensional array. How to do it?

Here is your fish:

my @array = (
[ qw(Quarter Dime Nickel Penny) ],
[ qw(test1 test2 test3 test4) ],
[ 1 .. 10 ],
[ 11, 22, 33, 44, 55 ],
);

Here is where you learn how to fish:

perldoc perldsc

Sinan
 
J

Jens Thoms Toerring

Tristan said:
how to put more arrays in one?
@array1 = qw(Quarter Dime Nickel Penny);
@array2 = qw(test1 test2 test3 test4);
@array3 = (1,2,3,4,5,6,7,8,9,10);
@array4 = (11,22,33,44,55);
I want to have only one multidimensional array. How to do it?

There are no true multidimensional arrays in Perl. But what you
can use instead is an arrary of array references, e.g.

my @array = ( [ qw( Quarter Dime Nickel Penny ) ],
[ qw( test1 test2 test3 test4 ) ],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ],
[ 11, 22, 33, 44, 55 ] );

Now e.g. $array[1][3] (or $array[1]->[3], if you prefer the
slightly longer version) is the string 'test4'.

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top