Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Help with Hash of hashes, is there a better way?

by roboticus (Chancellor)
on Jun 01, 2006 at 11:02 UTC ( [id://553021]=note: print w/replies, xml ) Need Help??


in reply to Help with Hash of hashes, is there a better way?

TeraMarv:

Since you're concerned about the effort of traversing the data structure and asked for alternative data structures, I have a couple of thoughts.

While it's nice to have a perfect representation of your system, it may be that your code doesn't really do anything fancy with $env, $platform, etc., and only need them in a couple of edge cases. In that case, you may want to flatten your data structure by combining the keys, allowing you to split out the parts you want if/when you need them. Something like the following (contrived) example where we need a disk usage warning report:

# Assumes top hash key is in the form: # hostname:platform:env # and the second-level hash key is: # target # and since the lowest level of your example is always the # same structure, we put the values in an array: # [0] = total_capacity # [1] = current_free_space while (my ($hostkey,$targets_href) = each %{$stuff}) { # *This* report doesn't care about prod/dev or OS, it's # just to warn about disk space problems, so only need # $host... Other reports may want other bits my ($host,undef) = split /:/,$hostkey; print "\n*****\n* $host\n*****\n\n" . "FreeSpc %Free Target\n" . "-------- ----- -----------------\n"; while (my ($target,$cap_href) = each %{targets_href}) { my $pct_free = $cap_href[1] * 100.0 / $cap_href[0]; if ($cap_href[1] < $warn_pct * $cap_href[0]) { printf "% 8u %5.3f %s\n", $cap_href[1], $pct_free, $target; } } }
--roboticus

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found