Do you need to look things up by coordinates? Do you need to be able to walk through the grid in order? Do you need to be able to jump to a particular row?

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:

my @arr; while (my ($x, $y, $beans) = read_grid_cell) { push @arr, [$x, $y, $beans]; } # Or the equivalent map statement, if you like.
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 %hash; while (my ($x, $y, $beans) = read_grid_cell) { $hash{$x}{$y} = $beans; }
If you need walkability as well as individual cell access, you would have to combine techniques:
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!

Caution: Contents may have been coded under pressure.

In reply to Re: 3d arrays by Roy Johnson
in thread 3d arrays by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.