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.
|