Created
May 17, 2013 15:05
-
-
Save briandfoy/5599667 to your computer and use it in GitHub Desktop.
Find all the perl files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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