Just a quick review: you are overwriting because of: %{$href} = %{JSON::PP->new->decode($json_data)};
Ie: as you noted, at each file iteration you are reassigning the content of $haref with new data.
You must instead do something like:
# untested foreach my $key ( keys %{JSON::PP->new->decode($json_data)} ){ # some collision check? if ( exists $$href{ $key }){ warn "$key already exists! was [$$href{ $key }] and will be [${JSO +N::PP->new->decode($json_data)}{$key}]\n"; } # assign a new key value pair $$href{$key} = ${JSON::PP->new->decode($json_data)}{$key}; }
Try, before dealing with your JSONS, with a bounch of test hashes until you get it working.
Also I'd avoid subs named encode and decode because of the risk of collision and for readability: if I see encode when using a JSON module I think about the module method ;)
HtH
L*
In reply to Re: Merge hashes in specific format
by Discipulus
in thread Merge hashes in specific format
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |