in reply to 1d array into 3d

Whether this will work correctly will depend upon how you are constructing your 1D array. Or rather, the source from which you are constructing it. Ie. If you are reading the data in from a file dumped from FORTRAN, you may need to invert the X and Z dimensions of the data.

I vaguely remember from my FORTRAN days, that the ordering of multi-dimensional array elements in FORTRAN is different from that in C. And I have no idea how that will translate to Perl's arrays.

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @D1 = split ' ', do{ local $/; <DATA> }; pp \@D1; my @D3 = map{ my $z = $_; [ map{ my $y = $_; [ @D1[ $z*9 + $y*3 .. $z*9 + $y*3 + 2 ] ] } 0 .. 2 ] } 0 .. 2; pp \@D3; __DATA__ z0y0x0 z0y0x1 z0y0x2 z0y1x0 z0y1x1 z0y1x2 z0y2x0 z0y2x1 z0y2x2 z1y0x0 z1y0x1 z1y0x2 z1y1x0 z1y1x1 z1y1x2 z1y2x0 z1y2z1 z1y2x2 z2y0x0 z1y0x1 z2y0x2 z2y1x0 z2y1x1 z2y1x2 z2y2x0 z2y2x1 z2y2x2

Output:

c:\test>754307.pl [ "z0y0x0", "z0y0x1", "z0y0x2", "z0y1x0", "z0y1x1", "z0y1x2", "z0y2x0", "z0y2x1", "z0y2x2", "z1y0x0", "z1y0x1", "z1y0x2", "z1y1x0", "z1y1x1", "z1y1x2", "z1y2x0", "z1y2z1", "z1y2x2", "z2y0x0", "z1y0x1", "z2y0x2", "z2y1x0", "z2y1x1", "z2y1x2", "z2y2x0", "z2y2x1", "z2y2x2", ] [ [ ["z0y0x0", "z0y0x1", "z0y0x2"], ["z0y1x0", "z0y1x1", "z0y1x2"], ["z0y2x0", "z0y2x1", "z0y2x2"], ], [ ["z1y0x0", "z1y0x1", "z1y0x2"], ["z1y1x0", "z1y1x1", "z1y1x2"], ["z1y2x0", "z1y2z1", "z1y2x2"], ], [ ["z2y0x0", "z1y0x1", "z2y0x2"], ["z2y1x0", "z2y1x1", "z2y1x2"], ["z2y2x0", "z2y2x1", "z2y2x2"], ], ]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."