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

In reply to Re: Help with Hash of hashes, is there a better way? by roboticus
in thread Help with Hash of hashes, is there a better way? by TeraMarv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.