Hi Michael,
  I've ran into a situation where I've needed to use your module. The problem I found with it is that it doesn't merge arrays, just replaces one with the other. I had a situation where I had two array references such as:-
$a1 = [undef, item2]; $a2 = [item1, undef];
I was ending up with
$a3 = [item1, undef];
When I wanted
$a3 = [item1, item2];
I've written an update that merges the arrays if items are undef like the example above. So far I've only tested with LEFT_PRECEDENT, but I don't see why it wouldn't work well for the others.

My changes to LEFT_PRECEDENT:-
'LEFT_PRECEDENT' => { 'SCALAR' => { 'SCALAR' => sub { $_[0] }, 'ARRAY' => sub { $_[0] }, 'HASH' => sub { $_[0] }, }, 'ARRAY' => { 'SCALAR' => sub { [ @{$_[0]}, $_[1] ] }, 'ARRAY' => sub { [ @{$_[0]}, @{$_[1]} ] }, 'HASH' => sub { [ @{$_[0]}, values %{$_[1]} ] }, }, 'HASH' => { 'SCALAR' => sub { $_[0] }, 'ARRAY' => sub { $_[0] }, 'HASH' => sub { _merge_hashes( $_[0], $_[1] ) }, }, },
New sub:-
sub _merge_arrays { my ( $left, $right ) = ( shift, shift ); if( ref $left ne 'ARRAY' || ref $right ne 'ARRAY' ) { carp 'Arguments for _merge_arrays must be array references'; return; } my $length = $#$left; $length = $#$right if ($#$right > $length); my @newarray; for (my $num = 0; $num <= $length; $num++) { if ( defined $left->[$num] && defined $right->[$num] ) { @newarray[ $num ] = merge ( $left->[ $num ], $right->[ $num] ); } elsif ( defined $left->[$num] && !(defined $right->[$num]) ) { @newarray[ $num ] = $left->[ $num ]; } elsif ( !(defined $left->[$num]) && defined $right->[$num] ) { @newarray[ $num ] = $right->[ $num ]; } else { $newarray[$num] = $clone_behavior ? _my_clone( $left->[$num] ) : $left->[$num]; } }#for return \@newarray; }
I'm guessing that this would make a good option for people. I wont implement it fully as it's your module after all. But if you do it implement it I'd greatly appreciate a mention, love reading my name on CPAN ;)

By the way I noticed that there is now a Pure Perl Clone module that doesn't need to be required in so I guess that you could use one or the other depending on availability to fix your ActiveState Clone problem.

Hope this helps.

In reply to Re: Hash::Merge by cosmicperl
in thread Hash::Merge by Masem

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.