This uses the File::Slurp::Tree modules to easily make recursive ascii trees of directories. It could probably be improved with some sorting so that all subdirs are printed first before the same level files. Written after reading this
node
#!/usr/bin/perl
use warnings;
use strict;
use File::Slurp::Tree;
# The tree datastructure is a hash of hashes. The keys of
# each hash are names of directories or files. Directories
# have hash references as their value, files have a scalar
# which holds the contents of the file.
my $dir = shift || '.';
my %tree;
my $tree = slurp_tree($dir);
my $depth = 0;
print "$dir\n";
print_keys($tree);
sub print_keys {
my $href = shift;
$depth++;
foreach ( keys %$href ) {
print ' ' x $depth, "--$_\n";
print_keys( $href->{$_} ) if ref $href->{$_} eq 'HASH';
}
$depth--;
}