in reply to Adding an new element to array.
Here is one good way to do it, but as always, tim toady.
use warnings; use strict; use Data::Dumper; $Data::Dumper::Sortkeys=1; my $data = { 'DATE' => '2013-04-25', 'TW' => '1', 'REF' => '1234567', 'ACC' => '33456790' }; $data = {%$data, DOC => 'EMAIL'}; print Dumper($data);
Alternatively, to add the second hash to the first, do something like this:
use warnings; use strict; use Data::Dumper; $Data::Dumper::Sortkeys=1; my $data = { 'DATE' => '2013-04-25', 'TW' => '1', 'REF' => '1234567', 'ACC' => '33456790' }; my $new = { DOC => 'EMAIL' ## NOTE: no need for quotes on thing ## to the left of `=>' }; $data = {%$data, %$new}; print Dumper($data);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding an new element to array.
by Anonymous Monk on Aug 21, 2013 at 18:19 UTC | |
by poj (Abbot) on Aug 21, 2013 at 19:13 UTC |