in reply to 3d arrays
How you want to get your data back is important in determining how you should store it. A simple array of arrays might suit you:
You could certainly print the grid back out later. But if you want to get at certain cells (but not be able to walk through in order), you might need a multi-dimensional hash:my @arr; while (my ($x, $y, $beans) = read_grid_cell) { push @arr, [$x, $y, $beans]; } # Or the equivalent map statement, if you like.
If you need walkability as well as individual cell access, you would have to combine techniques:my %hash; while (my ($x, $y, $beans) = read_grid_cell) { $hash{$x}{$y} = $beans; }
my @beans; my %grid; while (my ($x, $y, $beans) = read_grid_cell) { push @beans, [$x, $y, $beans]; $grid{$x}{$y} = $beans; } # Now you can walk through @beans, or you can lookup by $x and $y, # but don't change the beans in either spot, because they're not linke +d!
|
|---|