As a general rule, I always use a flattened simple "Table" structure (AoH ref or alternatively an AoA ref) with denormalized data. Nested structures like the one you depicted are usually overkill unless there is some elaborate OOP going on behind the scenes. Sometimes I will use an (HoAoH ref) and call that a "Workbook", but rarely does the need to re-invent a data structure go beyond that unless it is intrinsic to code optimization or other ancillary design constraints.

(Note: subject to personal preference, ymmv, the following are instructive guidelines, but not laws.)

Rationale:

Using this approach, any new 'data model' I have to work with usually consists of only four simple, reliable and repeatable steps: (define, populate, filter and process).

### define my $oTable000 = []; my $oRow = { 'typeof' => 'production', 'platform' => 'windows', 'foohost' => 'hostname', 'footarget' => 'targetname1', 'total_capacity' => 0, 'free_capacity' => 0, }; ### populate (with fake data) for (0 .. 12){ $oRow->{platform} = ${[qw(windows unix database)]}[int(rand(3))] +; $oRow->{typeof} = ${[qw(production development)]}[int(rand(2)) +]; my %hCurrent = %{$oRow}; $oTable000->[$_] = \%hCurrent; }; ### filter (do whatever querying or grouping you want here) @{$oTable000} = ### SORT BY sort { $a->{platform} cmp $b->{platform}} ### WHERE typeof = 'development' grep { $_->{typeof} eq 'development';} @{$oTable000}; ### process ### (send it off to your template engine, number crunch, whatever) foreach my $oRec (@{$oTable000}){ DoStuff($oRec); };
=oQDlNWYsBHI5JXZ2VGIulGIlJXYgQkUPxEIlhGdgY2bgMXZ5VGIlhGV

In reply to Re: Help with Hash of hashes, is there a better way? by dimar
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.