Hi tybalt89,
Sorry to post this so late but I couldn't find time to do this earlier. I have a question regards your technique to merge and the one that I posted.
With the method that I posted I specifically did not choose to use Hash::Merge and also specifically not { ( %{ $ ... }, %{ $ ... } ) } but instead to make it LEFT_PRECEDENT on the dir1 .. dirN. (Even though the design criteria said that these elements would be unique). The method that I created would ignore any new 'dir' element that already existed and so it will not corrupt already collected data.
If I would have used Hash::Merge I would have probably done something like:
use strict ; use warnings ; use Data::Dumper ; use List::Util qw { sum0 } ; use Hash::Merge ; my $VAR1 = { # Same as before }; my $VAR2 = { # same as before }; my $merger = Hash::Merge->new('RETAINMENT_PRECEDENT'); my $VAR3 = $merger->merge( $VAR1, $VAR2 ) ; foreach(keys %{$VAR3->{ total }}) { if ( ref $VAR3->{ total }->{ $_ } eq 'ARRAY' ) { $VAR3->{ total }->{ $_ } = sum0 @{$VAR3->{ total }->{ $_ }} ; } } print Dumper( $VAR3 ) ;
When receiving 'dir' elements again and using the technique of { ( %{ $ ... }, %{ $ ... } ) } would corrupt the data:
My question basically is, which of the three techniques is in your opinion more robust. Even though I directed this question to tybalt89, anyone else feel free to answer as well of course.
In reply to Re^2: Merge hashes in specific format
by Veltro
in thread Merge hashes in specific format
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |