I'm collecting a bunch of data from multiple servers. I need to store some of the server data and compare against other certain server data. So I don't need an array for each server I'd like to store it in a hash, but I'm having issues actually getting the data in/out of the hash.
foreach my $cluster_type (sort keys %{$href_server_list}){
foreach my $server (sort @{$href_server_list->{$cluster_type}}){
my @a_cmd_results = ();
get_server_data(\@a_cmd_results,$server);
if($cluster_type eq "TYPEA"){
push @{$GLOBAL_HASH_TYPEA_DATA{$server}}, @a_cmd_results;
}
elsif($cluster_type eq "TYPEB"){
push @{$GLOBAL_HASH_TYPEB_DATA{$server}}, @a_cmd_results;
}
my @TYPEA;
my @TYPEB;
my $server;
#loop through the 4 different servers
for(my $i=0;$i<4;$i++){
$server=$TYPEA_keys[$i];
push @TYPEA, @{$GLOBAL_HASH_TYPEA_DATA{$server}};#error here, "Cant use an undefined value as an ARRAY reference
$server=$TYPEB_keys[$i];
push @TYPEB, @{$GLOBAL_HASH_TYPEB_DATA{$server}};
#sort and compare data from TYPEA and TYPEB
}
It "works" if I push a reference instead of the array like this
push @{$GLOBAL_HASH_TYPEA_DATA{$server}}, \@a_cmd_results;
But if it's simply referencing the array @a_cmd_results then that's no good because it's continually reused for each server and would only contain the last server?