FMc*_*FMc 2 oop perl data-structures
在一个快速而肮脏的Perl脚本中,我有一个这样的数据结构:
$tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} = integer
Run Code Online (Sandbox Code Playgroud)
哈希键假设这样的值:
YEAR: 1900 .. 2000
STATE: AK, AL, ... WY
GOVLEV: state, local
TAX: type of tax (income, sales, etc.)
Run Code Online (Sandbox Code Playgroud)
此外,散列键是唯一的.例如,TAX
参数的值不会与另一个其他参数的值冲突.
我正在开始使用这些数据的中型项目,我想以更灵活的方式实现数据结构.我不知道我还需要的所有数据检索功能,但这里有一些例子:
# 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) );
Run Code Online (Sandbox Code Playgroud)
我最初的倾向是继续将数据存储为散列哈希,并构建一个或多个实用程序函数(可能作为类的一部分)来检索值.但后来我想知道是否有更好的策略 - 存储除散列哈希之外的基础数据的某种方式.任何关于如何处理这个问题的建议将不胜感激.