use warnings; use strict; use Text::Glob qw(glob_to_regex); sub do_a_dir { my $dir = shift; my @globs = @_; my @files = (); opendir my $dir, $dir or die "hrmph: $!"; while( my $ent = readdir $dir ) { next if $ent =~ m/\A\.\.?\z/; if( -d $ent ) { push @files, &do_a_dir(@globs) unless &a_glob_matches($ent, @globs); } elsif( -f $ent ) { if( $ent eq ".gitignore" ) { open my $in, $ent or die "hrmph: $!"; while(<$in>) { chomp; push @globs, glob_to_regex( $_ ); } close $in; } else { push @files, $ent unless &a_glob_matches($ent, @globs); # although, this is spurious. In practice, I would need # to find all the .gitignores in this dir before I # can test the files. } } else { # agahrr, I don't want to think about these monsters right now # I probably mean to skip them if I'm using opendir... } } closedir $dir; } sub a_glob_matches { my $ent = shift; my @globs = @_; for( @globs ) { return 1 if $ent =~ $_; } return 0; }