multidimensional Array

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

  1. Tristan

    Tristan Guest

    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
    #1
    1. Advertising

  2. "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?


    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 <>
    (remove .invalid and reverse each component for email address)
    clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
     
    A. Sinan Unur, Aug 9, 2007
    #2
    1. Advertising

  3. 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
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Bazell

    slice of multidimensional array

    Dave Bazell, Jul 23, 2003, in forum: Perl
    Replies:
    2
    Views:
    4,103
  2. epigram
    Replies:
    1
    Views:
    10,859
    =?Utf-8?B?c29jaWV0b3BpYS5uZXQ=?=
    Jul 16, 2005
  3. Ben
    Replies:
    8
    Views:
    12,768
    Eki Y. Baskoro
    Dec 18, 2003
  4. Huub
    Replies:
    6
    Views:
    621
  5. geletine
    Replies:
    12
    Views:
    21,720
    Fred Kleinschmidt
    May 5, 2006
Loading...

Share This Page