Print the versions of installed Perl modules

This Perl program prints out the versions of installed modules. You give it a list of modules on the command line, and it outputs the modules and their versions, or an error message if the module is not installed.

The output is formatted so that it can be copied and pasted directly into the PREREQ_PM of Makefile.PL. See The files in a Perl module for more about CPAN files.

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
my @modules = @ARGV;
for my $module (@modules) {
    eval "require $module";
    if ($@) {
        my $error = $@;
        if ($error =~ /Can't locate/) {
            warn "$module is not installed.\n";
        }
        else {
            warn "$module had a problem: $@.\n";
        }
        next;
    }
    my $version = $module->VERSION ();
    print "'$module' => '$version',\n";
}

(download)

The program output looks like this:

$ perl module-version.pl Gzip::Faster Template Scalar::Util
'Gzip::Faster' => '0.14',
'Template' => '2.26',
'Scalar::Util' => '1.42',

Web links


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer