In a quick-and-dirty Perl script, I have a data structure like this:
$tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} = integer
The hash keys assume values like this:
YEAR: 1900 .. 2000
STATE: AK, AL, ... WY
GOVLEV: state, local
TAX: type of tax (income, sales, etc.)
In addition, the hash keys are unique. For example, no value for the TAX
parameter collides with a value for another other parameter.
I am starting a medium-sized project working with this data and I would like to implement the data structure in a more flexible way. I don't know all of the data-retrieval functionality I will need yet, but here are some examples:
# Specify the parameters in any order.
Tax_rev( qw(1902 WY state property) );
Tax_rev( qw(state property 1902 WY) );
# Use named parameters.
Tax_rev(year => 1902, state => 'WY', govlev => 'state', tax => 'property');
# Use wildcards to obtain a list of values.
# For example, state property tax revenue in 1902 for all states.
Tax_rev( qw(1902 * state property) );
My initial inclination was to keep storing the data as a hash-of-hashes and to build one or more utility functions (probably as part of a class) to retrieve the values. But then I wondered whether there is a better strategy -- some way of storing the underlying data other than a hash-of-hashes. Any advice about how to approach this problem would be appreciated.