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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.