sub this_deep { my ($self, $depth) = @_; $depth = -1 unless @_ > 1; $self->{depth} = $depth; } sub next { my $self = shift; while( 1 ) { if ( @{ $self->{output} } ) { my $line = shift @{ $self->{output} }; return $line; } if ( ! @{ $self->{dirs} } ) { return; } my $dir = shift @{ $self->{dirs} }; if (-d $dir) { if( opendir( DIR, $dir ) ) { map { my $file = $_; my $fullfile = File::Spec->catfile( $dir, $file ); if (-d $fullfile && ($self->{level} <= $self->{depth} || $self->{depth} == -1)) { push (@{ $self->{dirs} }, $fullfile); } } File::Spec->no_upwards( readdir(DIR) ); closedir DIR; } else { warn "\a\a\aopendir FAILED, $dir: $!"; } } else { warn "\a\a\aNOT A DIRECTORY: $dir\n"; } } }