You mentioned having trouble "figuring out how to access information from a hash nested within another hash", and asked for an example. Once you learn this syntax, you'll be wanting to use it all over the place.

For purposes of a concrete example, say you have a hash of users. Their usernames are keys, but the values are hash refs with additional information. It would look something like this (written here by hand, but not too different from a Data::Dump output):

%users = ( rjt => { home => '/home/rjt', uid => 1000, shell => '/bin/bash', groups=> [ qw< sudo lpadmin > ], }, jdlev => { home => '/home/jdlev', uid => 1001, shell => '/bin/csh', groups=> [ qw< users lpadmin > ], }, );

Note that the "groups" key refers to an array reference with the groups the user belongs to. Here are some examples of accessing the various data:

print "rjt's uid is $users{rjt}{uid}\n"; local $" = ', '; # List separator print "jdlev is a member of: @{$users{jdlev}{groups}}.\n"; push @{$users{jdlev}{groups}}, 'sudo'; # jdlev now belongs to sudo as +well

As for how to dump the data, Data::Dump gets my vote, most often anyway. I have some local debugging libraries that do various other data munging tasks to create more concise dumps in certain cases, but 99% of the time I could live with Data::Dump. It not being core doesn't concern me because none of the dump() calls survive to production code in my case.

use strict; use warnings; omitted for brevity.

In reply to Re: Data Dump / Tool To View Hash Structure Easily? by rjt
in thread Data Dump / Tool To View Hash Structure Easily? by jdlev

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.