To create a Three Dimensional Array in Perl, you can use arrays or nested arrays.
In this example,
# Creating a 3D Array with Nested Arrays
use strict;
use warnings;
my @three_d_array;
for my $i (0..2) {
for my $j (0..1) {
for my $k (0..3) {
$three_d_array[$i][$j][$k] = 0;
}
}
}
# Modify an element
$three_d_array[1][0][2] = 5;
# Print the array
for my $i (0..2) {
for my $j (0..1) {
print join(' ', @{$three_d_array[$i][$j]}), "\n";
}
print "\n";
}
0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In this tutorial, we learned How to create a Three Dimensional Array in Perl language with well detailed examples.