in reply to Messing about in Arrays of Hashes

It sounds like what you really want to do is go from an array of hashes into a single hash:
my %master_hash; for my $anon_hash_ref ( @AoH ) { $master_hash{ $$anon_hash_ref{id} } += $$anon_hash_ref{value}; }
Now, %master_hash is keyed by the set of unique ids from the AoH, and its values are the sums of the values for matching ids.

update (because you updated the question while I was making up the initial answer): assuming that "id_a" always relates to "value_x" and "id_b" to "value_y":

for my $anonhash ( @AoH ) { $master_hash{ $$anonhash{id_a} } += $$anonhash{value_x}; $master_hash{ $$anonhash{id_b} } += $$anonhash{value_y}; }
another update: (because the previous update was wrong): Since the "id_a" and "id_b" values in your AoH might "intersect", this will keep them distinct:
for my $anonhash ( @AoH ) { $master_hash{ "a".$$anonhash{id_a} } += $$anonhash{value_x}; $master_hash{ "b".$$anonhash{id_b} } += $$anonhash{value_y}; }
FINAL UPDATE: (sheesh!) Okay, based on your later clarification about the problem, I'd still suggest building a single hash as output, but now it should be either a HoH or HoA (whatever you prefer):
for my $anonhash ( @AoH ) { my $newkey = join '_', 'a', $$anonhash{id_a}, 'b', $$anonhash{id_b +}; # one way (HoH): $master_hash{$newkey}{value_x} += $$anonhash{value_x}; $master_hash{$newkey}{value_y} += $$anonhash{value_y}; # another way (HoA): $master_hash{$newkey}[0] += $$anonhash{value_x}; $master_hash{$newkey}[1] += $$anonhash{value_y}; }
(Of course, you'll want to delete or comment out whichever pair of lines above you don't prefer.)

Replies are listed 'Best First'.
Re^2: Messing about in Arrays of Hashes
by nzgrover (Scribe) on Sep 21, 2004 at 04:35 UTC
    Sorry about whipping the carpet out like that, I had tried to simplify the real world problem of course and realized after I had posted that I had gone to far.