# Defining 3D array

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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!

## Re: Defining 3D array

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

## Re: Defining 3D array

> 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

## Re: Defining 3D array

Try

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

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

Ie: change "=(" to "=[" and ");" to "];".

--
http://www.lowth.com/blist/-/4045/1 : The best perl scripting books

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