http://qs321.pair.com?node_id=490545

bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monasterians,

Is there a way to find out which version of a Perl module is running on a server? (besides calling tech support or having a new feature fail :-) Am particularly interested in CGI.pm. Thanks.

UPDATE: It's crazy that searching the CGI docs and doing a SuperSearch didn't turn up that incredibly simple solution. Thanks all.


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: Finding version of a Perl module
by b10m (Vicar) on Sep 09, 2005 at 12:39 UTC
    perl -MCGI -e'print $CGI::VERSION';
    --
    b10m

    All code is usually tested, but rarely trusted.

      Since $VERSION is usually near the top, I often just do this instead:

      perldoc -m CGI

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Finding version of a Perl module
by merlyn (Sage) on Sep 09, 2005 at 13:25 UTC

      Caveat: merlyn's trick only works is the module uses Exporter or immitates Exporter's version checks (Added for clarity:) by writting an import which calls UNIVERSAL::VERSION.

      Update: Apparently, perl will call UNIVERSAL::VERSION for you if the version is passed as a number, not a string.

        I don't think so. The version check is done by UNIVERSAL::VERSION , which is called by use when you specify a version number when using a module.

        From "perldoc -f use":

        If the VERSION argument is present between Module and LIST, then the "use" will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable $Module::VERSION.
Re: Finding version of a Perl module
by Fletch (Bishop) on Sep 09, 2005 at 12:51 UTC

    I have this shell function (zsh, but it should work for most Korn-ish shells):

    pmver () { perl -le "eval { require ${1} }; if( \$@ =~ /locate (\S+)\.pm/ ) { p +rint qq{${1} not installed}; exit 1; } print qq{${1}: },\$${1}::VERSI +ON||q{undefined}" }

    It's used like this:

    $ pmver CGI CGI: 3.05 $
Re: Finding version of a Perl module
by jmcnamara (Monsignor) on Sep 09, 2005 at 13:19 UTC

    I usually use this:
    perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::M +odule

    --
    John.

Re: Finding version of a Perl module
by lachoy (Parson) on Sep 09, 2005 at 13:24 UTC

    Just to add another version -- one of my first tasks when using a new machine is to scp the following script somewhere on the path as 'pmv':

    #!/usr/bin/perl for my $module ( @ARGV ) { eval "require $module"; printf( "%-20s: %s\n", $module, $module->VERSION ) unless ( $@ ); }

    A sample use:

    cwinters@www ~ $ pmv CGI Template DBI CGI : 3.05 Template : 2.14 DBI : 1.48

    Chris
    M-x auto-bs-mode

Re: Finding version of a Perl module
by blazar (Canon) on Sep 09, 2005 at 12:51 UTC
    How 'bout inspecting $That::Particular::Module::VERSION?
Re: Finding version of a Perl module
by ybiC (Prior) on Sep 09, 2005 at 14:04 UTC
    It looks like The Fine Monks have already addressed your particular situation.   But since a particular module hasn't yet been mentioned above, see below for mention of a potentially relevant module worth mentioning:

    Module::Versions::Report

    SYNOPSIS use Module::Versions::Report; ...and any code you want... This will run all your code normally, but then as the Perl interpreter + is about to exit, it will print something like: Perl v5.6.1 under MSWin32. Modules in memory: attributes; AutoLoader v5.58; Carp; Config; DynaLoader v1.04; Exporter v5.562; Module::Versions::Report v1.01; HTML::Entities v1.22; HTML::HeadParser v2.15; HTML::Parser v3.25; [... and whatever other modules were loaded that session...] Consider its use from the command line: % perl -MModule::Versions::Report -MLWP -e 1 Perl v5.6.1 under MSWin32. Modules in memory: attributes; AutoLoader v5.58; [...]

      cheers,
      ybiC

      striving toward Perl Adept
      (it's pronounced "why-bick")