Perl one liner to display module version info

April 29th, 2009 by Rohan

I use this Perl one-liner to display the version number of a module. This module should be available in your @INC paths.

If I need to know the version of CGI.pm

$ perl -MCGI -e ‘print “$CGI::VERSION\n”‘
3.29

I created a shell script so that I can just type the module name.

$ cat pm_version.sh
#!/bin/sh
MODULE=$1
perl -M$MODULE -e ‘print “$’$MODULE’::VERSION\n”‘

So now, I can do this.

$ pm_version.sh Google::Adwords
v1.13

[Post to Twitter] Tweet This Post  [Post to Facebook] Facebook 

7 Responses to “Perl one liner to display module version info”

  1. Moritz Onken Says:

    try this instead:

    perl -MDBIx::Class\ 999

    This will output the following:

    DBIx::Class version 999 required–this is only version 0.081.

  2. Rohan Says:

    Cool!

    You’re asking perl to load version 999 and it complains with the current version number. But what if one day DBIx::Class does indeed reach beyond version 999? :p

  3. matt Says:

    One of the helper scripts in the pmtools distribution on CPAN, pmvers, does the same thing. Worth checking out, it comes with other useful tools like pmpath (prints the on-disk location of a specified module).

  4. thrig Says:

    Next, write a script that returns the path to a particular Perl module. This way, you can quickly determine the version and where the code lives in the file system.

  5. Rohan Says:

    Thats easy. You have the -l and -m arguments to the perldoc command.

    $ perldoc -l Data::Dumper

    will display the full path to the Dumper.pm file

    $ perldoc -m Data::Dumper

    will open Dumper.pm in your default pager

  6. The Lady of the Camellias » Blog Archive » v6 (Perl) Says:

    […] Rohan Almeida's Blog » Blog Archive » Perl one liner to display … […]

  7. Another perl Blog » Blog Archive » AaronZ Sakai: Installing perl modules in OSX Says:

    […] Rohan Almeida's Blog » Blog Archive » Perl one liner to display … […]

Leave a Reply




Tweet This Post links powered by Tweet This v1.4.1, a WordPress plugin for Twitter.