Perl one liner to display module version info
April 29th, 2009 by RohanI 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

April 29th, 2009 at 5:01 pm
try this instead:
perl -MDBIx::Class\ 999
This will output the following:
DBIx::Class version 999 required–this is only version 0.081.
April 29th, 2009 at 6:08 pm
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
April 29th, 2009 at 8:01 pm
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).
April 30th, 2009 at 7:00 am
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.
April 30th, 2009 at 12:17 pm
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
May 9th, 2009 at 3:51 pm
[…] Rohan Almeida's Blog » Blog Archive » Perl one liner to display … […]
May 13th, 2009 at 4:57 pm
[…] Rohan Almeida's Blog » Blog Archive » Perl one liner to display … […]