I'm stuck on visualizing data structure for my table. I'm writing a Perl program that will compare aspects of different cities. I have a pdf file for each city, which contains couple of data tables. I have to scan the data, store it in some data structure, so that later user will have an option of what aspect of the cities to compare. Here's an example table to better visualize this:

CITY A Population by Age and Gender Age Group Male Female Total 0-9 220 180 400 10-19 175 142 317 20-29 260 265 525 Family Households Family Type Households % of Total Married 145 10 Divorced 60 7 Single 162 15

My code goes through the file, line by line, and recognizes what part of the table it is (Header, data, etc.). I have a problem with how I should be storing all this data. There are couple of important points. First, each table can have different number of rows and columns, but each table will have at least two columns and rows. Second, later user will specify a table (ex. Population by Age and Gender) and row and column (ex Age Group 10-19 and Male) so that this extracted value will be compared to all other cities. I'm fairly new to complex data structures in Perl. I'm not sure if I should use Hash of Hashes, Hash of Arrays, or Hash of Arrays of Hashes. I've been stuck on this part for some time, and can't visualize the proper data structure.

I just need a visualization of a data structure that I should use, no code necessary. The most important part is that later, it will be easy to display available tables, and rows and columns for the user to pick.

I come up with the data structure below, but it will not be easy to later show the user available rows and columns. Thanks.

{ "Population by Age and Gender" => { Age Group => ["0-9", "10-19", "20-29"], Male => [220, 175, 260], + Female => [180, 142, 265] } "Family Households" => {"Family Type" => [Married, Divorced, Single], Households => [145, + 60, 162] } }

In reply to Building data structure from multi-row/column table by rwx---

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.