My own personal feeling on this: I tend to look at hashes the same way I looked at hashes the same way I looked at structs in C programming. It's a handy-dandy way of grouping related information together so you can act on that group as a single unit. This is not to be confused with C++ classes in any way.

Since hashes are put together on the fly Perl has no way of enforcing all of the elements are present when the hash is created. Let's look at an example of what I'm talking about:

my $company = { employees => { fred => { fullname => "Freddy Freeloader", position => "panhandler", management => "no" }, clem => { realname => "Clem Kaddiddlehopper", job => "questionable", has_reports => "no" } } };
In the first employee record we see the fields fullname, position and manageent and in the second record we see realname, job and has_reports. OK, so which is real and which is Memorex?

In spite of that if I am going to group together data without resorting to creating a Perl module I'll use a HoH structure, but just be sure you are keeping track of what you are putting in there.

You asked which is faster. I think this is a non-sequitor in this case. If you are using field name such as client_goldman_phone and friends you are burdening yourself as a programmer to coming up with a way to search all of the names, append subfields and all sorts of cruft that gets in the way of good programming. Think maintainability. When I write Perl code my assumption is that someday someone else may have to maintain it. If you are doing crufty things then you are leaving behind crufty code for folks inheriting your code to deal with and your name will be dragged through programming mud.

Coding keys %{$company{employees}} is easier to write and much easier to read than some sort of fugazy  my @keys = grep "employees", keys %company; in my humble opinion.

HTH


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: multidimensional hash emulation vs hash of hashes by blue_cowdawg
in thread multidimensional hash emulation vs hash of hashes by dexahex

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.