Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl: Pushing a 1d array into a 3d sub-array
    text
    copied!<p>I am trying to push/unshift a 1D array in a 2D array which is a sub-array of a 3D array. You can check a example code in <a href="http://codepad.org/5s8Og64k" rel="nofollow">http://codepad.org/5s8Og64k</a> to make this more clear, I copy it also here:</p> <pre><code>use Data::Dumper; # @arr_3d ; $arr_3d[0][0][0] = 1; $arr_3d[0][1][0] = 2; $arr_3d[0][0][1] = 4; $arr_3d[0][1][1] = 3; # @arr_1d ; $arr_1d[1] = "new1"; $arr_1d[0] = "new0"; print Dumper(\@arr_3d); unshift @{$arr_3d[0]},\@arr_1d; print Dumper(\@arr_3d); </code></pre> <p>In other words, if we define the 3D array's dimensions x-y-z and consider x constant then we get a "2D" array . I want to push a 1D array into this 2D "sub-array" of the original 3D array.</p> <p>The example code actually does that, <strong>BUT</strong> when I try applying it to my main script, the dumper dumps "<strong>$VAR1->[0][0]</strong>" in the place of all the previously pushed-in data, and only dumps the data from the last pushed-in 1D array.</p> <p>Any idea what is could be causing that or of a more effective way to do the push I describe?</p> <p><em>Extra info:</em> The actual data structure is created within a loop, something like:</p> <pre><code>unshift @{$arr_3d[$index]},\@arr_1d; print @arr_1d; # This prints successfully the 1D array </code></pre> <p>where "@arr_1d" is created be simply assigning individual elements:</p> <pre><code>$arr_1d[0]='a'; $arr_1d[1]='b'; # etc, etc.. </code></pre> <p>Thanks for your time, Giorgos</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload