To use the test program, supply a path to the script on the command line, but choose a smallish one because Data::Dumper uses prodigious amounts of memory to dump the structure.
The hashdir() function should be portable as far as it goes, but it doesn't check for things like symbolic links, devices etc...
#! perl -slw
use strict;
use Data::Dumper;
sub hashdir{
my $dir = shift;
opendir my $dh, $dir or die $!;
my $tree = {}->{$dir} = {};
while( my $file = readdir($dh) ) {
next if $file =~ m[^\.{1,2}$];
my $path = $dir .'/' . $file;
$tree->{$file} = hashdir($path), next if -d $path;
push @{$tree->{'.'}}, $file;
}
return $tree;
}
my $tree = hashdir( shift );
print Dumper $tree;