in reply to Creating and Accessing 3-D array
How many row arrays do you create in total? 3. How many rows do you want? 9, 3 per sheet. Do you see the problem?
Another hint would be that your loop structure for populating the array is different than your loop structure for getting from the array, yet you are looping over the same array. How can that be?
Fix:
for my $sheet (1..3) { my @sheet; for my $row (1..3) { my @row; for my $col (1..3) { push @col, 0; } push @sheet, \@row; } push @sheets, \@sheet; }
Thanks to autovivification, this can actually be simplified.
for my $sheet (1..3) { for my $row (1..3) { for my $col (1..3) { $sheets[$sheet][$row][$col] = 0; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating and Accessing 3-D array
by Anonymous Monk on Feb 06, 2011 at 13:51 UTC | |
by ikegami (Patriarch) on Feb 07, 2011 at 02:26 UTC |