my $bin_directory = {
"cat" => undef,
"cp" => undef,
"date" => undef,
... and so on ...
};
Similarly, the Skipper's home directory might also
contain a personal bin directory (at something
like ~skipper/bin) that contains personal tools:
my $skipper_bin = {
"navigate" => undef,
"discipline_gilligan" => undef,
"eat" => undef,
};
nothing in either structure tells where the directory is located in
the hierarchy. It just represents the contents of some directory.
Go up one level to the Skipper's home directory,
which is likely to contain a few files along with the personal
bin directory:
my $skipper_home = {
".cshrc" => undef,
"Please_rescue_us.pdf" => undef,
"Things_I_should_have_packed" => undef,
"bin" => $skipper_bin,
};
If there is a subdirectory, the nested subroutine call uses
readdir to extract the contents of that directory
and returns a hash reference, which is inserted into the hash
structure created by the caller.
At first, it may look a bit mystifying, but if you walk through the
code slowly, you'll see it's always
doing the right thing.
Test the results of this subroutine by calling it on
. (the current directory) and seeing the result:
use Data::Dumper;
print Dumper(data_for_path("."));