【发布时间】:2018-01-17 18:13:51
【问题描述】:
我正在尝试找到 Perl 填充多级哈希的最佳方法,同时考虑到缺少的键。
所以我用这个:
if( !exists $customer_data{$customer_id} ) {
$customer_data{$customer_id} = {};
}
$customer_data{$customer_id}->{$salesman_name} //={};
$customer_data{$customer_id}->{$salesman_name}->{$timestamp} = 1;
这很奇怪,因为我正在使用 exists 和 //= 东西,但我不确定如何正确简洁地编写此代码。
结果类似于:
'1000' => {
'jsmith' => {
1502121730 => 1,
1512321730 => 1
}
}
【问题讨论】: