Code to print the leaf nodes in a tree, enjoy.
#!/usr/bin/perl
################################################################################
use strict;
use warnings;
################################################################################
use Path::Class; #file(), dir()
use Cwd; #getcwd()
################################################################################
# prototypes
################################################################################
sub report_leaf_dirs();
my $start_dir = dir( $ARGV[0] || getcwd() );
#print "DEBUG: Scanning $start_dir\n";
$start_dir->recurse( callback => \&report_leaf_dirs );
##################
#
##################
sub report_leaf_dirs() {
my $object = shift;
# print "DEBUG: processing $object\n";
return unless $object->is_dir();
# Test to see if we can read it
unless( $object->open() ) {
warn "Unable to open $object\n";
return;
}
# Test for sub directories
foreach my $child ( $object->children() ) {
return if $child->is_dir();
}
print "$object\n";
}