in reply to Re: Merge Hashrefs
in thread Merge Hashrefs
Gives (see below) with "aaa" key in 'aa'=>'aaa'=>22 lostuse strict; use Data::Dumper; my $x = { a => 1, b => 2, aa => { aaa => 11 } }; print Dumper($x); my $y = { c => 3, d => 4, aa => { bbb => 11 } }; print Dumper($y); $x = { %$x, %$y }; print Dumper($x);
UPDATE: check this thread how to do it using Hash-Merge http://www.perlmonks.org/?node_id=1015801 In a nut shell, add as appropriate:$VAR1 = { 'c' => 3, 'a' => 1, 'b' => 2, 'd' => 4, 'aa' => { 'bbb' => 11 } };
and modifyuse Hash-Dumper qw/merge/;
to$x = { %$x, %$y };
and resulting hash will look much better$x = merge( $x, $y );
$VAR1 = { 'c' => 3, 'a' => 1, 'b' => 2, 'd' => 4, 'aa' => { 'bbb' => 11, 'aaa' => 11 } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Merge Hashrefs
by LanX (Saint) on Oct 15, 2014 at 15:40 UTC |