Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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;


$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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2016-02-13 09:49 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (423 votes), past polls