Later in the script I try to retrieve the information and get weird results. After trying everything I could think of to troubleshoot, I pasted in the following section 3 times:} elsif($gateway_cluster) { #print "adding gwc :$addr: :$fqn: :$customer_name: :$object_name: : +$fw_ver:\n"; $cluster_info{$addr} = { fqn => "$fqn", customer_name => "$customer_name", cluster_name => "$object_name", fw_ver => "$fw_ver", } #} elsif.....
This printed the contents of the hash three times, with an entry counter; one printing after another. The 1st time had eight entries. The 2nd and 3rd were identical with 58 entries each, of which entries 51 - 58 corresponded to the entries 1 - 8 in the 1st printing. It is as if the first time through %cluster_info is getting accessed from the 51st position instead of the 1st. Then I changed the printing loop by adding this line at the top, right after setting the counter:print "##############################################################\ +n"; if(VERBOSE) { my $counter = 1; print "The cluster_info tables:\n------------------------\n"; while ( my ($IP, $hashref) = each %cluster_info) { printf "%-3s %-20s %-18s %s", "$counter", "cluster IP:", ":$I +P:", "\n"; for my $param ( sort keys %{ $hashref } ) { printf "%-20s %-18s %s", "$param" . ":", ":$cluster_info{$ +IP}{$param}:", "\n"; } $counter++; print "=====================================================\ +n"; } }
Then everything became correct. This problem has been reproduced using recent 5.8.x versions of ActivePerl on Windows XP and 2000, and recent ActivePerl on Solaris 8, and using the most recent Cygwin with Perl on Windows 2000. What am I doing wrong?print "size of hash: " . keys( %cluster_info ) . ".\n";
In reply to Wrong hash output by mathew_
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |