G'day Monks,
I have been writing a script to monitor the capacities of various disks and databases in my work environment. During this process i have found myself working with the following Hash of Hashes
$stuff = { production => { windows => { Hostname => { targetname1 = { total_capacity = value, free_capacity = value }, targetname2 = { total_capacity = value, free_capacity = value } } }, unix => { Hostname => { targetname1 = { total_capacity = value, free_capacity = value }, targetname2 = { total_capacity = value, free_capacity = value } } }, database => { Hostname => { targetname1 = { total_capacity = value, free_capacity = value }, targetname2 = { total_capacity = value, free_capacity = value } } } }, development => { windows => { etc. etc.}, unix => { etc. etc.}, database => { etc. etc.} } } ;
While this perfectly describes the information i'm working with it becomes a bit unwieldy when working with it. I have had to resort to a bunch of nested 'while' loops
while(my($env,$platform_href) = each %{$stuff}) { while(my($platform,$host_href) = each %{$platform_href}) { while(my($host,$target_href) = each %{$host_href}) { while(my($target,$capacity_href) = each %{$target_href}) { # Do stuff with # $env # $platform # $host # $target # $capacity_href->{'total_capacity'}; # $capacity_href->{'free_capacity'}; } } } }
Nasty eh?
Is there a better/prettier way of traversing the data structure or even a better way of representing the data with a different structure?
Many Thanks,
TeraMarv
In reply to Help with Hash of hashes, is there a better way? by TeraMarv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |