Defining 3D array

Discussion in 'Perl Misc' started by Duke of Hazard, Sep 18, 2004.

  1. I have searched google, but could not find an answer for how to define
    a 3D array manually. Here is the code:

    $schedule[0]= (
    ["0", "0", "0","0"],
    ["0", "0", "0","0"],
    );

    $schedule[1]= (
    ["0", "0", "0","0"],
    ["0", "0", "0","0"],
    );

    The problem is $schedule[$i][$j][$k] are all undefined for any values
    of i,j, and k?

    Thanks!
     
    Duke of Hazard, Sep 18, 2004
    #1
    1. Advertising

  2. Duke of Hazard wrote:

    > I have searched google, but could not find an answer for how to define
    > a 3D array manually. Here is the code:
    >
    > $schedule[0]= (
    > ["0", "0", "0","0"],
    > ["0", "0", "0","0"],
    > );
    >
    > $schedule[1]= (
    > ["0", "0", "0","0"],
    > ["0", "0", "0","0"],
    > );


    You want to store an array reference in $schedule[0], where above you're
    trying to store an array. Like this:

    $schedule[0] = [
    [0,0,0,0],
    [0,0,0,0],
    ];
    $schedule[1] = [
    [0,0,0,0],
    [0,0,0,0],
    ];

    You could also do it all at once:

    $schedule = [
    [
    [0,0,0,0],
    [0,0,0,0],
    ],[
    [0,0,0,0],
    [0,0,0,0],
    ],
    ];

    See 'perldoc perldsc' and 'perldoc perllol' for more about nested data
    structures.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Sep 18, 2004
    #2
    1. Advertising

  3. Duke of Hazard

    Anno Siegel Guest

    Duke of Hazard <> wrote in comp.lang.perl.misc:
    > I have searched google, but could not find an answer for how to define
    > a 3D array manually. Here is the code:
    >
    > $schedule[0]= (
    > ["0", "0", "0","0"],
    > ["0", "0", "0","0"],
    > );
    >
    > $schedule[1]= (
    > ["0", "0", "0","0"],
    > ["0", "0", "0","0"],
    > );
    >
    > The problem is $schedule[$i][$j][$k] are all undefined for any values
    > of i,j, and k?


    Switch on strictures and warnings and run it again.

    Anno
     
    Anno Siegel, Sep 20, 2004
    #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. Boogie El Aceitoso

    Error while defining char array

    Boogie El Aceitoso, Dec 3, 2003, in forum: C++
    Replies:
    6
    Views:
    406
    Jumbo
    Dec 3, 2003
  2. johny smith
    Replies:
    8
    Views:
    421
    Peter Koch Larsen
    Jul 2, 2004
  3. bruce
    Replies:
    2
    Views:
    282
    tac-tics
    Jul 5, 2006
  4. bruce
    Replies:
    1
    Views:
    402
    Nick Craig-Wood
    Jul 5, 2006
  5. Spiro Trikaliotis

    Array initialization when defining the array

    Spiro Trikaliotis, Jun 8, 2007, in forum: C Programming
    Replies:
    5
    Views:
    323
    Spiro Trikaliotis
    Jun 9, 2007
Loading...

Share This Page