SPUG: Merging two array of hashes

Eric.D.Peterson at alltel.com Eric.D.Peterson at alltel.com
Tue Apr 11 14:43:03 PDT 2006


 

Never mind,  Just fill the same AoH after calling the get_data function.
I have got to stop looking at this and think of something else for a few
minutes.





-----Original Message-----
From: Peterson, Eric D 
Sent: Tuesday, 11 April 2006 14:24
To: 'spug-list at pm.org'
Subject: Merging two array of hashes


Using DBI (fetchall_arrayref) which returns an array reference, I call
twice to two different machines with the same query to get similar data.
I want to merge the data before outputting.  Unfortunately I can't
create a database link otherwise I'd do the query once. So I'll have to
do it here in my calling routine.

I can use Data::Dumper to output the Array of Hash.  But instead I'd
like to merge the two AoH into one, then sort the data, and then print
the properly.  So for now I need a hint on how to merge the two AoH.



...
# ---------- ---------- ----------
my $onyx_data_ref = get_data ( "userid", "dbname", "unixname", 0, "Onyx"
); my @onyx_AoH; foreach my $row ( @$onyx_data_ref ) {
    my ( $machine, $workflow_nm, $cnt, $last_run, $diff, $status ) =
@$row;
    push @onyx_AoH, { machine  => $machine, 
                      workflow => $workflow_nm,
                      count    => ( $cnt =~ s/^\s+// ), 
                      last_run => $last_run,
                      diff     => $diff, 
                      status   => $status };
}

# ---------- ---------- ----------
my $onyx_data_ref = get_data ( "userid", "dbname", "unixname", 0, "Opal"
); my @opal_AoH; foreach my $row ( @$opal_data_ref ) {
    my ( $machine, $workflow_nm, $cnt, $last_run, $diff, $status ) =
@$row;
    push @opal_AoH, { machine  => $machine, 
                      workflow => $workflow_nm,
                      count    => ( $cnt =~ s/^\s+// ), 
                      last_run => $last_run,
                      diff     => $diff, 
                      status   => $status };
}

use Data::Dumper;
$Data::Dumper::Varname = "ONYX ---"; print Dumper \@onyx_AoH;
$Data::Dumper::Varname = "OPAL ---"; print Dumper \@opal_AoH; ...





*****************************************************************************
The information contained in this message, including attachments, may contain privileged or confidential information that is intended to be delivered only to the person identified above. If you are not the intended recipient, or the person responsible for delivering this message to the intended recipient, ALLTEL requests that you immediately notify the sender and asks that you do not read the message or its attachments, and that you delete them without copying or sending them to anyone else. 




More information about the spug-list mailing list