Advertisement
justin_hanekom

perl-modules-installed.pl

May 13th, 2019 (edited)
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.93 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use Modern::Perl '2009';    # Enable Perl 5.10 features
  4. use strict;                 # Included so that perlcritic does not complain
  5. use warnings;               #                 ditto
  6. use 5.010;                  # Only works under Perl 5.10 and later
  7. use autodie qw( :all );     # Make system functions either succeed or die
  8. use strictures 2;           # Turn on strict and make most warnings fatal
  9.  
  10. use English;
  11.  
  12. # Determine the list of module names
  13.  
  14. my @module_names;
  15. foreach my $inc_dir (@INC) {
  16.     my @file_names;
  17.     eval {
  18.         @file_names = `find $inc_dir -name '*.pm' 2>/dev/null`;
  19.     };
  20.     continue if ($EVAL_ERROR);
  21.     foreach my $found (@file_names) {
  22.         chomp $found;                   # remove the trailing newline
  23.  
  24.         $found =~ s{                    # substitute...
  25.                     \A $inc_dir         # ...a beginning dir name
  26.                    }
  27.                    {}xms;               # replacing it with nothing
  28.  
  29.         $found =~ s{                    # substitute...
  30.                     \.pm \z               # ... an ending .pm
  31.                    }
  32.                    {}xms;               # replacing it with nothing
  33.  
  34.         $found =~ s{                    # substitute...
  35.                     /                   # ... each slash (/)
  36.                    }
  37.                    {::}gxms;            # replacing it with ::
  38.  
  39.         $found =~ s{                    # substitute...
  40.                     \A ::               # ... a beginning ::
  41.                    }
  42.                    {}xms;               # replacing it with nothing
  43.  
  44.         push @module_names, $found;     # and add to the module names list
  45.     }
  46. }
  47.  
  48. # Finally, print a lexicographically sorted list of the module names
  49.  
  50. for my $module_name ( sort @module_names ) {
  51.     say $module_name;
  52. }
  53.  
  54. # vim: set filetype=perl smartindent autoindent smarttab expandtab tabstop=4 softtabstop=4 shiftwidth=4 autoread
Tags: perl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement