I agree with the other responses, your way looks fine. Sometimes it is worth considering "self documenting data" which can help document your code.

For example

next unless $item->{is_a_switch};
gives you a good indication of what the question is and what sort of answer you can expect.

As has been pointed out, with this approach you are more than halfway to having an object.

#!/usr/local/bin/perl use strict; use warnings; my %network = get_network(); for my $blade (keys %network){ for my $item (@{$network{$blade}}){ next unless $item->{is_a_switch}; print qq{$item->{item_name}\n}; for my $kit (@{$item->{more_kit}}){ print qq{ kit: $kit->{kit_name}\n}; } } } sub get_network { my %network = ( 01/01 => [ { is_a_switch => 0, item_name => q{router}, more_kit => 0, }, { is_a_switch => 1, item_name => q{hpswitch1}, more_kit => [ { port => q{port1}, kit_name => q{workstation1}, }, { port => q{port2}, kit_name => q{workstation2}, }, ], } ], 01/02 => [ { is_a_switch => 1, item_name => q{hpswitch2}, more_kit => [ { port => q{port1}, kit_name => q{server4}, }, { port => q{port2}, kit_name => q{server5}, }, ], } ], 01/03 => [ { is_a_switch => 0, item_name => q{server2}, more_kit => 0, }, ], ); return %network; }
output
hpswitch1 kit: workstation1 kit: workstation2 hpswitch2 kit: server4 kit: server5

In reply to Re: generating hashes of hashes by wfsp
in thread generating hashes of hashes by mrnick1234567

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.