Velocity Reviews > Perl > multidimensional Array

# multidimensional Array

Tristan
Guest
Posts: n/a

 08-09-2007
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. Sinan Unur
Guest
Posts: n/a

 08-09-2007
"Tristan" <(E-Mail Removed)> wrote in news:f9fd5a\$ltv\$(E-Mail Removed)-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?

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

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

Jens Thoms Toerring
Guest
Posts: n/a

 08-09-2007
Tristan <(E-Mail Removed)> 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://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de