# Update a hash by adding or replacing mappings. Hash references # stored in the top level hash can be updated recursively, if desired. # Params: # %h = The hash to modify # $depth = Recursion depth. # @kv = New key value pairs. sub hpush(\%$@); sub hpush(\%$@) { my ($h, $depth, @kv) = @_; while (@kv) { my ($k, $v) = splice @kv, 0, 2; if ($depth > 0 and ref($h->{$k}) eq 'HASH' and ref($v) eq 'HASH') { hpush %{$h->{$k}}, $depth - 1, %{$v}; } else { $h->{$k} = $v; } } }