O'Reilly logo

Perl Cookbook by Nathan Torkington, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program: Finding Versions and Descriptions of Installed Modules

Perl is shipped with many modules. Even more can be found on CPAN. The following program prints out the names, versions, and descriptions of all modules installed on your system. It uses standard modules like File::Find and includes several techniques described in this chapter.

To run it, type:

% pmdesc

It prints a list of modules and their descriptions:

            
               FileHandle (2.00) - supply object methods for filehandles
            
               IO::File (1.06021) - supply object methods for filehandles
            
               IO::Select (1.10) - OO interface to the select system call
            
               IO::Socket (1.1603) - Object interface to socket communications
            ...

With the -v flag, pmdesc provides the names of the directories the files are in:

% pmdesc -v


               <<<Modules from /usr/lib/perl5/i686-linux/5.00404>>>

            
               FileHandle (2.00) - supply object methods for filehandles
                ...

The -w flag warns if a module doesn’t come with a pod description, and -s sorts the module list within each directory.

The program is given in Example 12.3.

Example 12-3. pmdesc

#!/usr/bin/perl -w
# pmdesc - describe pm files # tchrist@perl.com use strict; use File::Find qw(find); use Getopt::Std qw(getopts); use Carp; use vars ( q!$opt_v!, # give debug info q!$opt_w!, # warn about missing descs on modules q!$opt_a!, # include relative paths q!$opt_s!, # sort output within each directory ); $| = 1; getopts('wvas') or die "bad usage"; @ARGV = @INC unless @ARGV; # Globals. wish I didn't really have to do this. use vars ( q!$Start_Dir!, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required