Created
March 10, 2016 17:32
-
-
Save dnmfarrell/9ad567a2f9afb9e35fe6 to your computer and use it in GitHub Desktop.
Perl script to list all *pm files under a directory
This file contains 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
#!/usr/bin/env perl | |
use 5.10.3; | |
use Path::Tiny 'path'; | |
use Getopt::Long 'GetOptions'; | |
GetOptions( | |
'dir=s' => \my $dirpath, | |
) or die "Unrecognized option\n"; | |
die "--dir is required\n" unless $dirpath && -d $dirpath; | |
# append a slash if missing | |
$dirpath .= '/' unless substr($dirpath, -1) eq '/'; | |
my $iter = path($dirpath)->iterator({recurse => 1}); | |
while (my $path = $iter->()) { | |
next unless "$path" =~ qr/.pm$/; | |
# remove the parent dir and trailing .pm from filename | |
my $module = substr("$path", length($dirpath), length("$path")-length($dirpath)-3); | |
$module =~ s/\//::/g; | |
say $module; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment