#!/usr/bin/perl -w use strict; use Data::Dumper; sub data_for_path { my $path = shift; if (-f $path or -l $path) { #files or symbolic links return undef; } if (-d $path) { my %directory; opendir PATH, $path or die "cannot opendir $path: $!"; my @names = readdir PATH; closedir PATH; for my $name (@names) { next if $name eq '.' or $name eq '..'; $directory{$name} = data_for_path("$path/$name"); } return \%directory; } warn "$path is neither a file nor a directory\n"; return undef; } print Dumper(data_for_path('.')); #### $VAR1 = { 'perl.1' => undef, 'bin' => { 'perl.1' => undef, 'chaos.1' => undef }, 'perl.sub_sub' => undef, 'perl.sub_multi' => undef, 'chaos.1' => undef, 'perl.filehandle' => undef, 'man' => {}, 'lib' => { 'yahoo3' => { 'yahoo3' => { 'yahoo1111' => undef }, 'yahoo5' => undef }, 'yahoo2' => undef, 'yahoo' => undef }, 'perl.log' => undef, 'perl.recursive_data' => undef, 'perl.callbacks' => undef };