Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: how to merge hash deeply ?

by Kenosis (Priest)
on Jan 29, 2013 at 04:49 UTC ( #1015801=note: print w/ replies, xml ) Need Help??


in reply to how to merge hash deeply ?

One option is to use Hash::Merge:

use strict; use warnings; use Hash::Merge qw/merge/; use Data::Dumper; #file1: read as $conf_file1 my %hash1 = ( db => { name => 'pdte', host => 'localhost', } ); #file2: read as $conf_file2 my %hash2 = ( db => { port => '5432', user => 'pdte_usr', password => 'pdte_213456', } ); my %mergedHash = %{ merge( \%hash1, \%hash2 ) }; print Dumper \%mergedHash;

Output:

$VAR1 = { 'db' => { 'password' => 'pdte_213456', 'user' => 'pdte_usr', 'name' => 'pdte', 'port' => '5432', 'host' => 'localhost' } };


Comment on Re: how to merge hash deeply ?
Select or Download Code
Re^2: how to merge hash deeply ?
by chinaxing (Acolyte) on Jan 31, 2013 at 07:11 UTC
    very thanks ! that's what i was finding

      You're most welcome!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2014-10-20 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls