in reply to Hash::Merge

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.