Skip to content

Instantly share code, notes, and snippets.

@dnmfarrell
Created March 10, 2016 17:32
Show Gist options
  • Save dnmfarrell/9ad567a2f9afb9e35fe6 to your computer and use it in GitHub Desktop.
Save dnmfarrell/9ad567a2f9afb9e35fe6 to your computer and use it in GitHub Desktop.
Perl script to list all *pm files under a directory
#!/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