# multidimensional Array

Discussion in 'Perl Misc' started by Tristan, Aug 9, 2007.

1. ### TristanGuest

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.

Tristan, Aug 9, 2007

2. ### A. Sinan UnurGuest

"Tristan" <> wrote in news:f9fd5a\$ltv\$-com.hr:

> 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?

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

--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)

A. Sinan Unur, Aug 9, 2007

3. ### Jens Thoms ToerringGuest

Tristan <> wrote:
> 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
--
\ Jens Thoms Toerring ___
\__________________________ http://toerring.de

Jens Thoms Toerring, Aug 9, 2007