#!/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--; }