» VIEW ALL POSTS
Oct 11 2007 2:41PM GMT
Posted by: admin
scripts, Linux basics
Script tracks Perl modules for you
Posted by: admin
Michael Hurley shares a script that he wrote called modlister. I’ll let him explain:
It’s a script to tell you what Perl modules you have installed and where, to query whether you have a particular module installed, to see associated files, etc. For example:
-
- List all installed modules:
- Only show filenames (strip directories):
- See if Compress::Zlib is installed:
- See all the files associated with Zlib:
modlister.pl
modlister.pl -f
modlister.pl -m Zlib
modlister.pl -m Zlib -a
Thanks for the script, Michael.
Try this one out yourself. Tell us what you think or submit one of your own. If we use your script, you will receive a gift a Starbucks gift certificate. More scripting goodness after the jump…
#!/usr/bin/perl
###############################################################
## modlister.pl
##
## Purpose: List installed perl modules
## Author: Michael Hurley
## Copyright 2006
##
## modlister.pl is free software. you can redistribute it
## and/or modify it under the terms of the GNU General Public
## License as published by the Free Software Foundation;
## either version 2, or (at your option) any later version.
##
###############################################################
use strict;
use warnings;
use File::Find;
use Getopt::Std;
use vars qw/%opt/;
my $optstr = 'm:fah';
&getopts("$optstr", %opt);
&usage if $opt{h};
my (%m, @mods);
find(&wanted, @INC);
if ($opt{m}) {
@mods = grep {/$opt{m}/} keys %m;
} else {
@mods = keys %m;
}
for (@mods) {
print "$_n";
}
sub wanted {
if ($opt{f} && !$opt{a}) {
$m{$_} = 1 if /.pm$/;
} elsif ($opt{a} && !$opt{f}) {
$m{$File::Find::name} = 1;
} elsif ($opt{f} && $opt{a}) {
$m{$_} = 1;
} elsif (/.pm$/) {
$m{$File::Find::name} = 1;
}
}
sub usage {
my $msg = <<EoMSG
Usage: $0 [-m <arg>] [-f] [-a]
By default, $0 prints the full path for every
.pm file in @INC. You can modify the behavior
with these flags:
-m List modules that match
-f List filenames only (not the full path)
-a List all files in @INC, not just .pm files
-h Print this help message
EoMSG
;
die $msg;
}
__END__
=head1 NAME
modlister.pl - List installed perl modules
=head1 SYNOPSIS
modlister.pl [-m
] [-f] [-a]
=head1 DESCRIPTION
modlister.pl prints installed perl modules. By default, modlister.pl
will print the full path of any files in @INC that end in F<.pm>.
Its behavior can be modified with these flags:
=over 4
=item B<-m> I
Only print strings that match I
.
=item B<-f>
Only print filenames; exclude directories.
=item B<-a>
Print all files in the directory, not just F<.pm> files.
=back
=head1 AUTHOR
Michael Hurley
=head1 LICENSE
Copyright 2006 Michael Hurley.
This is free software. You can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2,
or (at your option) any later version.



You must be logged-in to post a comment. Log-in/Register