在一个快速而肮脏的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 …Run Code Online (Sandbox Code Playgroud)