Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So it turns out <code>Hash::Merge</code> was only mangling my data on Windows using an outdated version of the Clone module.</p> <p>With up-to-date versions (or on my Mac right off the bat) the following code does exactly what I need:</p> <pre><code>#!/usr/bin/env perl -w use strict; use JSON; use Hash::Merge qw( merge ); Hash::Merge::set_behavior('RIGHT_PRECEDENT'); # Load full config into hashref open (IN, "&lt;:utf8", "full-config.txt"); my $app_data; while(&lt;IN&gt;) {$app_data .= $_;} my $app_json = decode_json($app_data); close IN; # Sample portion of config options to override/extend my $app_override = '{"config": { "bookToolbar": { "bookmark": { "enabled":false }, "help": { "data": { "url":"aGreatHelpFile.html" }, "enabled":true }, "closeBook": { "enabled":true } } }, "pagelist":[ { "hasOnPageNotes" : true, "pageName" : "25", "hasTextMarkup" : true, "hasScreenReader" : false, "hasLinks" : false, "pageId" : "0025" } ] }'; my $app_override_hash = from_json($app_override, {utf8 =&gt; 1}); # Merge with right precedent, $app_json hash ref has everything we need. $app_json = merge( $app_json, $app_override_hash ); </code></pre> <p>I found this table exceptionally helpful to analyze the different precedence options in <code>Hash::Merge</code> (this is <a href="http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm" rel="nofollow">straight from the docs</a>:</p> <pre><code> LEFT TYPE RIGHT TYPE LEFT_PRECEDENT RIGHT_PRECEDENT SCALAR SCALAR $a $b SCALAR ARRAY $a ( $a, @$b ) SCALAR HASH $a %$b ARRAY SCALAR ( @$a, $b ) $b ARRAY ARRAY ( @$a, @$b ) ( @$a, @$b ) ARRAY HASH ( @$a, values %$b ) %$b HASH SCALAR %$a $b HASH ARRAY %$a ( values %$a, @$b ) HASH HASH merge( %$a, %$b ) merge( %$a, %$b ) LEFT TYPE RIGHT TYPE STORAGE_PRECEDENT RETAINMENT_PRECEDENT SCALAR SCALAR $a ( $a ,$b ) SCALAR ARRAY ( $a, @$b ) ( $a, @$b ) SCALAR HASH %$b merge( hashify( $a ), %$b ) ARRAY SCALAR ( @$a, $b ) ( @$a, $b ) ARRAY ARRAY ( @$a, @$b ) ( @$a, @$b ) ARRAY HASH %$b merge( hashify( @$a ), %$b ) HASH SCALAR %$a merge( %$a, hashify( $b ) ) HASH ARRAY %$a merge( %$a, hashify( @$b ) ) HASH HASH merge( %$a, %$b ) merge( %$a, %$b ) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload