在Perl中,我有散列 像阵列散列
0 HASH(0x98335e0)
'title' => 1177
'author' => 'ABC'
'quantity' => '-100'
1 HASH(0x832a9f0)
'title' => 1177
'author' => 'ABC'
'quantity' => '100'
2 HASH(0x98335e0)
'title' => 1127
'author' => 'DEF'
'quantity' => '5100'
3 HASH(0x832a9f0)
'title' => 1277
'author' => 'XYZ'
'quantity' => '1030'
数组现在我需要积累,其中标题和作者是相同的数量。 在与标题= 1177和作者=哈希上述结构“ABC”的数量可以累积成一个,并应在整个结构看起来像下面
0 HASH(0x98335e0)
'title' => 1177
'author' => 'ABC'
'quantity' => 0
1 HASH(0x98335e0)
'title' => 1127
'author' => 'DEF'
'quantity' => '5100'
2 HASH(0x832a9f0)
'title' => 1277
'author' => 'XYZ'
'quantity' => '1030'
什么是我能做到这一点的积累,这样的最佳方式它被优化?数组元素的数量可能非常大。我不介意添加一个额外的密钥来帮助相同的哈希,但我不想n查找。请告知
你说“我不想n查找”,但是没有访问数组的每个成员都无法在整个数组中累积。 – 2010-07-08 15:48:27
请将[perldoc perldsc](http://perldoc.perl.org/perldsc.html)和[perldoc perlreftut](http://perldoc.perl.org/perlreftut.html)添加到您的阅读列表中。 – Ether 2010-07-08 16:12:51