Do you want to add the numbers with the same keys?
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %parent = ( 'file3232.ext' => { e => 0, k => '0.0031', i => '26.9', j => '33.0', } ); my %returned = ( 'file3232.ext' => { e => 0, k => '0.1040', i => '26.7', j => '14.6', } ); for my $file (keys %returned) { for my $dataset (keys %{ $returned{$file} }) { $parent{$file}{$dataset} += $returned{$file}{$dataset}; } } print Dumper \%parent;
Using Hash::Merge is the following: retrieve the most similar predefined behaviour, modify it to your needs (e.g. define the addition of scalar values) and use it to merge the hashes:
use Hash::Merge qw{ merge }; my $behavior = Hash::Merge::get_behavior_spec('STORAGE_PRECEDENT'); $behavior->{SCALAR}{SCALAR} = sub { $_[0] + $_[1] }; Hash::Merge::add_behavior_spec($behavior); %parent = %{ merge(\%parent, \%returned) }; print Dumper \%parent;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
In reply to Re: Merging multidimensional hashes from forks to parent hash
by choroba
in thread Merging multidimensional hashes from forks to parent hash
by Speed_Freak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |