The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Hash::Override - Merges nested data structures. Useful if you need to merge default config files with user-defined settings.

SYNOPSIS

  use Hash::Override;

  my $A = {
    key1 => [ 1,2,3,4   ],
    key2 => 'v1',
  };
  my $B = {
    key1 => [ 5,6 ],
    key2 => 'v1',
  };
  merge_hash_override($A,$B);

DESCRIPTION

This module was designed to be used for merging json configuration files which had overlapping keys or overlapping values. There are many ways to do this depending on the situation so read through the documentation to find out if it is what you need(It was for me at the time of writing this).

merge($left,$right)

Takes 2 hashrefs as parameters, and transfers keys/values from the second to the first one, modifying it inplace. This method does not have a return value. This method acts recursively, on both parameters at the same time, going deep into their structure to copy whatever data is needed from $right to $left.

All the leafs from $right are written to $left. If there are keys in $left have value undef, then they will take the value from $right Arrays will be overwritten only with the additional values(positions after the current existing positions in left).

Read tests to find out more on the behaviour.

EXPORTS

This module exports the sub merge_hash_override which is an alias to Hash::Override::merge

AUTHOR

Stefan Petrea, <stefan.petrea at gmail.com>