#!/usr/bin/env perl use Modern::Perl '2009'; # Enable Perl 5.10 features use strict; # Included so that perlcritic does not complain use warnings; # ditto use 5.010; # Only works under Perl 5.10 and later use autodie qw( :all ); # Make system functions either succeed or die use strictures 2; # Turn on strict and make most warnings fatal use English; # Determine the list of module names my @module_names; foreach my $inc_dir (@INC) { my @file_names; eval { @file_names = `find $inc_dir -name '*.pm' 2>/dev/null`; }; continue if ($EVAL_ERROR); foreach my $found (@file_names) { chomp $found; # remove the trailing newline $found =~ s{ # substitute... \A $inc_dir # ...a beginning dir name } {}xms; # replacing it with nothing $found =~ s{ # substitute... \.pm \z # ... an ending .pm } {}xms; # replacing it with nothing $found =~ s{ # substitute... / # ... each slash (/) } {::}gxms; # replacing it with :: $found =~ s{ # substitute... \A :: # ... a beginning :: } {}xms; # replacing it with nothing push @module_names, $found; # and add to the module names list } } # Finally, print a lexicographically sorted list of the module names for my $module_name ( sort @module_names ) { say $module_name; } # vim: set filetype=perl smartindent autoindent smarttab expandtab tabstop=4 softtabstop=4 shiftwidth=4 autoread