Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Adding an new element to array.

by protist (Monk)
on Aug 21, 2013 at 17:58 UTC ( #1050395=note: print w/ replies, xml ) Need Help??


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);


Comment on Re: Adding an new element to array.
Select or Download Code
Re^2: Adding an new element to array.
by Anonymous Monk on Aug 21, 2013 at 18:19 UTC
    OK may be I am not been clear but this is the reason:
    my $data = $dbh->exec("select * ......"); if($data) { my $more_data = $dbh ->exec("select * ...."); if($more_data) { my $name = $more_data->[0]{ NAME }; push @{$data}, {doc_type => $name}; } } print Dumper(@$data);
    Thanks!
      #!perl use strict; use Data::Dump 'pp'; my $data = [{ 'DATE' => '2013-04-25', 'TW' => '1','REF' => '1234567', 'ACC' => '33456790' }]; my $more_data = [{'DOC1' => 'EMAIL1','DOC2' => 'EMAIL2'}]; my @keys = keys %{$more_data->[0]}; @{$data->[0]}{@keys} = @{$more_data->[0]}{@keys}; pp @$data;
      poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-09-16 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (13 votes), past polls