Got it.

Ok, I'm thinking you want a multi-dimensional hash. Here's basically what I'm talking about:

%windows = ( "office 1" => ("120 120" => 3, "140 135" => 1, "155 135" => 1), "bedroom 2" => ("100 75" => 2, "120 180" => 1), );
That is a pre-loaded hash just to show you what the structure will look like. Of course you'll need to load that hash from scratch with your script as you read through the text file.

So in hash %windows, key "office 1" has a value which is a *reference* to an anonymous hash (a *reference* to an anonymous hash is created by the parenthesis), and that reference refers to the anonymous hash which has these key/value's:

Key Value ------- ----- 120 120 3 140 135 1 155 135 1
Then to print out the %windows hash you will need two loops - one loop to iterate through the outer hash(with keys "office 1" and "bedroom 2", and an inner loop to iterate through the hash elements within each of those outer loop elements - something like this:
foreach my($room, $measurements_hashref) (each %windows) { print "$room\n"; print "width\theight\tquantity\n"; foreach my($measurements, $count) (each %$measurements_hashref) +{ print "$measurements $count\n"; } }
***Careful - this is completely untested code, but hopefully it's close.

HTH.


In reply to Re: Data Structures Help by hmerrill
in thread Data Structures Help 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.