Ask Your Question
0

how to merge hashes with chaining indexes?

asked 2014-08-12 09:05:34 -0500

updated 2014-08-12 09:05:56 -0500

Hi,

Regarding to the following links, is it possible to merge 2 hashes into one:

  1. https://docs.puppetlabs.com/puppet/la...
  2. https://forge.puppetlabs.com/puppetla...

that's working fine:

$test = {a => 1} + {b => 2}
notice ($test)
results in: {a => 1, b => 2}

but if I want to merge a hash with chaining indexes, there is another result:

$test = {test => {a => 1}} + {test => {b => 2}}
notice ($test)
results in: test => {b => 2}
I would expect: test => {a => 1, b => 2}

(same result with the stdlib merge() function)

Am i wrong or did I miss a part in the documentation?

Cheers

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-04-03 19:15:58 -0500

updated 2015-04-04 09:16:52 -0500

No, that's a wrong expectation. The plus-operator on arrays only works on the basis level of the involved arrays.

test => {a=>1} is a key-value pair and
test => {b=>2} is one, too.
Both have the same key. That is what matters.

The + doesn't care about what the values are.

Exactly as what you've experienced with your first example.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-12 09:05:34 -0500

Seen: 368 times

Last updated: Apr 04 '15