Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
Replies are listed 'Best First'.
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 romping around the Monastery: (16)
As of 2015-07-31 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls