Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > multidimensional Array

Reply
Thread Tools

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.

 
Reply With Quote
 
 
 
 
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)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>

 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java multidimensional string array geletine Java 12 05-05-2006 09:14 PM
Binding Multidimensional Array to DataGrid epigram ASP .Net 1 07-15-2005 11:02 PM
multidimensional array as argument Huub Java 6 05-29-2004 07:58 PM
Returning a multidimensional array. Ben Java 8 12-18-2003 08:48 AM
slice of multidimensional array Dave Bazell Perl 2 07-24-2003 11:17 PM



Advertisments