Thank you Discipulus and the Anonymous Monk(s).

I was at least able to comment the code as to what it was doing, and I only needed to make some slight modifications to my code to make it work as I Wanted it to work.

I'll just drop in the subroutine and make notes directly on it.

sub parse_tree { # note:make sure trailing slash is removed from passed arg my ($root_path) = @_; my %root; my %dl; my %count; # This is the wanted for find. my $path_checker = sub { # grab item name my $name = $File::Find::name; # If directory -- if (-d $name ) { # Assign current root hash as reference to r my $r = \%root; # hold the item in temp my $tmp = $name; # Remove the root path section of the file to get rid of the # first part of the path $tmp =~ s/^\Q$root_path\E//; # If a leading '/' is left, remove that. $tmp =~ s/^\///; # if the entry in the hash is undefined, create a new empty # hash from the splitted path of tmp. $r = $r->{$_} ||= {} for split m|/|, $tmp; #/ # if $dl{$name} is undefind, the assign $r to $dl{$name}. $dl{$name} ||= $r; } elsif (-f $name) { # If $name is a file, find the directory path my $dir = $File::Find::dir; # increment the file count based on that directory. my $key = "file". ++$count{ $dir }; # create a new entry in the hash $dl{$dir}{$key} = $_; } }; find($path_checker, $root_path); return \%root; }

In reply to Re: Using File::Find to create a hash of directory structure. by AnaximanderThales
in thread Using File::Find to create a hash of directory structure. by AnaximanderThales

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.