rwx--- has asked for the wisdom of the Perl Monks concerning the following question:
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] } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building data structure from multi-row/column table
by Athanasius (Archbishop) on Apr 03, 2015 at 03:39 UTC | |
|
Re: Building data structure from multi-row/column table
by LanX (Saint) on Apr 03, 2015 at 03:55 UTC | |
|
Re: Building data structure from multi-row/column table
by roboticus (Chancellor) on Apr 03, 2015 at 11:28 UTC | |
by GotToBTru (Prior) on Apr 03, 2015 at 19:00 UTC | |
by roboticus (Chancellor) on Apr 03, 2015 at 19:05 UTC |