$r = $r->{$_} ||= {} for split m|/|, $tmp; #/ $dl{$name} ||= $r; #### #!/usr/bin/perl # # Initial perl settings -- Using strict and warning # to ensure I'm writing proper perl. use strict; use warnings; use diagnostics; use Data::Dumper; use File::Find; my $dirHash = {}; # Hash file of directory my $testDir = $ENV{"HOME"} . "/bin/"; # Grab a list of files and put into hash $dirHash = parse_tree("$testDir"); # Dump -- for testing print "directory hash dump\n" . Dumper $dirHash; # Functions sub parse_tree { my ($root_path) = @_; my %root; my %dl; my %count; my $path_checker = sub { my $name = $File::Find::name; if (-d $name ) { my $r = \%root; my $tmp = $name; $tmp =~ s/^\Q$root_path\E//; $r = $r->{$_} ||= {} for split m|/|, $tmp; #/ $dl{$name} ||= $r; } elsif (-f $name) { my $dir = $File::Find::dir; my $key = "file". ++$count{ $dir }; $dl{$dir}{$key} = $_; } }; find($path_checker, $root_path); return \%root; } exit 0;