Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created May 17, 2013 15:05
Show Gist options
  • Save briandfoy/5599667 to your computer and use it in GitHub Desktop.
Save briandfoy/5599667 to your computer and use it in GitHub Desktop.
Find all the perl files
use v5.10;
use File::Find qw(find);
use File::MMagic;
my $MM = File::MMagic->new;
my $files = [];
say "ARGV [@ARGV]";
find( generator( $files ), @ARGV );
say join "\n", @$files;
sub generator {
my( $array_ref ) = @_;
my %prune_dirs = map { $_, 1 } qw(
.git
.svn
);
my $wanted = sub {
$file = $File::Find::name;
if( exists $prune_dirs{$_} ) { $File::Find::prune = 1; return }
unless ($file =~ / [.]p(lx?|m) \z/xi) {
my $type = $MM->checktype_filename($file);
return unless $type =~ /executable|perl/;
if( $type !~ m/perl/ and $type =~ m/\bexecutable\b/ ) {
open my $fh, '<', $file or warn "$file: $!";
chomp( my $shebang = <$fh> );
return unless $shebang =~ /perl/;
}
}
return unless -f $file;
push @$array_ref, $file;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment