http://www.perlmonks.org?node_id=1004434


in reply to Append to hash reference

use Data::Dumper; my $ref1 = { foo => 1, bar => 2 }; my $ref2 = { baz => 3, quux => 4 }; # Assign to the ref1 hash the data in both hashes %$ref1 = (%$ref1, %$ref2); print Dumper $ref1;

Or...

use Data::Dumper; my $ref1 = { foo => 1, bar => 2 }; my $ref2 = { baz => 3, quux => 4 }; # Loop through the keys of the second hash, assigning values into the +first $ref1->{$_} = $ref2->{$_} for keys %$ref2; print Dumper $ref1;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Append to hash reference
by Anonymous Monk on Nov 18, 2012 at 19:15 UTC

    Or...

    use Data::Dumper; my $ref1 = { foo => 1, bar => 2 }; my $ref2 = { baz => 3, quux => 4 }; # Use a hash slice to override values from the first hash with the sec +ond hash @$ref1{ keys %$ref2 } = values %$ref2;