http://www.perlmonks.org?node_id=885420

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

When trying to locate the version number I keep using this:
perl -MLong::And::Stupid::Module::Name -e "print $Long::And::Stupid::M +odule::Name::VERSION"
on Windows and
perl -MLong::And::Stupid::Module::Name -e 'print $Long::And::Stupid::M +odule::Name::VERSION'
on Linux I even have a small shell script doing this for me but it is not always with me.
#! /bin/sh perl -m$1 -le 'print '$1'->VERSION || die "No VERSION in '$1'\n"'
Is there any better way to do that?

perldoc showing version number?

In many modules I see people embed the version number in the POD so the reader will know. This can quickly get out of sync with the real version number. Would it be better/possible to have perldoc extract the version number of a module - when displaying the docs of a module - and show that along the documentation?

Replies are listed 'Best First'.
Re: How to get the version of an installed module?
by ikegami (Patriarch) on Feb 01, 2011 at 07:08 UTC

    If you just want to do a quick and dirty check,

    perl -e'use Module 999'

    The error message will include the module's version number.

      Just to clarify ikegami's response: The command line tells perl that you want version 999 of the module in question. When perl can't find that version, it reports the version you do have:

      $ perl -e 'use Spreadsheet::ParseExcel 999' Spreadsheet::ParseExcel version 999 required--this is only version 0.5 +7 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

      (I didn't recognize what the command line was doing until I executed it to see the error message. I knew you could specify the version on the use line, but thought there was more syntax to it.)

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Re: How to get the version of an installed module?
by Khen1950fx (Canon) on Feb 01, 2011 at 08:56 UTC
    See App::DualLivedList.

    For example, the version numbers for Catalyst::Runtime:

    dual-lived Catalyst::Runtime
    It'll accurately give you the current and installed version numbers.
Re: How to get the version of an installed module?
by planetscape (Chancellor) on Feb 01, 2011 at 11:35 UTC
Re: How to get the version of an installed module?
by JavaFan (Canon) on Feb 01, 2011 at 12:34 UTC

      That would have been my suggestion too. I use it all the time. You can even combine multiple modules:

      $ perl -MV=DBI,DBD::CSV,DBD::Pg DBI /pro/lib/perl5/site_perl/5.12.2/i686-linux-64int-ld/DBI.pm: 1. +616 DBD::CSV /pro/lib/perl5/site_perl/5.12.2/DBD/CSV.pm: 0.31 DBD::Pg /pro/lib/perl5/site_perl/5.12.2/i686-linux-64int-ld/DBD/Pg.pm: + 2.17.1 $

      Enjoy, Have FUN! H.Merijn
Re: How to get the version of an installed module?
by JavaFan (Canon) on Feb 01, 2011 at 12:43 UTC
    In many modules I see people embed the version number in the POD so the reader will know. This can quickly get out of sync with the real version number.
    Write a test. Or a little script that either synchronizes, or increments version numbers.
    Would it be better/possible to have perldoc extract the version number of a module - when displaying the docs of a module - and show that along the documentation?
    Probably not. But you can always do something like (untested):
    {no warnings; <<'=pod'} =pod our $VERSION = '1.2.3'; =pod =cut
    The first =pod tricks most, if not all, podlators into thinking POD starts. They're all fooled, and perl knows. The second =pod starts the real POD section. =cut syncs perl and the podlators.