I am trying to build a big hash to be exported based on the keys and values from another hash, This is the jist of it:
the function takes array @data as input from each value of the keys in %outserv. it then cleans out and strips the data I need and puts it into its own hash, which is returned by the function. The script then pushed the contents of the hash onto the master hash, and after the loop is finished, you end up with %refined. The first time it goes through the loop, it runs without incident, but after that, the output looks as if it is referencinv the first one I test. WHen I do a Dumper on it, the subsequent values for $refined{$key} just say: $VAR1->{'server1'}[0] The key variable outputs correctly to the hash, but the values for it after the first do not. I suspect it to be a referencing problem. Here is my codefor the while loop:
Here is sub man_data:
Can anyone help?
the function takes array @data as input from each value of the keys in %outserv. it then cleans out and strips the data I need and puts it into its own hash, which is returned by the function. The script then pushed the contents of the hash onto the master hash, and after the loop is finished, you end up with %refined. The first time it goes through the loop, it runs without incident, but after that, the output looks as if it is referencinv the first one I test. WHen I do a Dumper on it, the subsequent values for $refined{$key} just say: $VAR1->{'server1'}[0] The key variable outputs correctly to the hash, but the values for it after the first do not. I suspect it to be a referencing problem. Here is my codefor the while loop:
Code:
while (($key,@data) = (each %outserv)){
%manout = &man_data(@data);
#push the entire cluster check on the final hash
$href = \%manout;
push(@{$refined{$key}},$href);
}
print &Dumper(\%refined)." \n";
Here is sub man_data:
Code:
sub man_data{
my ($clusterdata,$identifier,$servicegroup,$clustnode,$junk1,$junk2,$sysstate,$nodestatus,$frozen,$category);
my (%stripped,%A,%B,%C,$hashref);
my @incoming = split(/\n/,$_[0][0]);
#manipulate the data, store it in hash.
foreach $clusterdata (@incoming){
#strip out and eliminate junk
chomp $clusterdata;
$clusterdata =~ s/^\s+//;
#grab group states and put them into their individual hashes
if($clusterdata =~ /^A/){
($identifier,$clustnode,$sysstate,$frozen) = split(/\s+/,$clusterdata);
$nodestatus = "$sysstate~$frozen";
push (@{$A{$clustnode}},$nodestatus);
}elsif($clusterdata =~ /^B/){
($identifier,$servicegroup,$clustnode,$junk1,$junk2,$sysstate) = split(/\s+/,$clusterdata);
$nodestatus = "$clustnode~$sysstate";
push (@{$B{$servicegroup}},$nodestatus);
}elsif($clusterdata =~ /^C/){
($identifier,$servicegroup,$junk1,$junk2,$clustnode) = split(/\s+/,$clusterdata);
push (@{$C{$servicegroup}},$clustnode);
}else{
next;
#Trash It!
}
}
#initialize the hash for pushing all of then subhashes onto it.
#push it all onto one big hash
if(%A){
$hashref = \%A;
push(@{$stripped{"A"}},$hashref);
}
if(%B){
$hashref = \%B;
push(@{$stripped{"B"}},$hashref);
}
if(%C){
$hashref = \%C;
push(@{$stripped{"C"}},$hashref);
}
#return the entire hash
return (%stripped);
}#END - man_data
Can anyone help?