Defining 3D array

D

Duke of Hazard

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

Sherm Pendley

Duke said:
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--
 
A

Anno Siegel

Duke of Hazard said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top