Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Building data structure from multi-row/column table

by LanX (Saint)
on Apr 03, 2015 at 03:55 UTC ( [id://1122325]=note: print w/replies, xml ) Need Help??


in reply to Building data structure from multi-row/column table

I think you have to separate heads and data of a table.

your current structure is problematic, because HoHs are unsorted and you can't distinguish what the row/column headers are

{ columns => { Male => 0, Female => 1 }, rows => { "0-9" => 0, "10-19" => 1, "20-29" => 2 }, data => [ [220, 175, 260], [180, 142, 265] ] }
(untested)

You need to look-up indices to get the data now.

This could be encapsulated in a tied hash or an object class.¹

"Age Group" makes it a bit more complicated, not sure what it is, how would you call it?

Maybe a "CATEGORY" field of the rows?

I hope you get the point and this helps. :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Je suis Charlie!

PS: pretty sure someone will come up with a CPAN² module now... :)

update

¹) for instance you could bless the hash above into a class My::Table . Then $obj->rows returns a list of names, and $obj->entry("Male","0-9") returns the entry, and so on.

²) like Data::Table

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1122325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found