Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

checking module version

by diamantis (Beadle)
on Jun 13, 2007 at 12:14 UTC ( #620930=perlquestion: print w/ replies, xml ) Need Help??
diamantis has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I want to check if a few modules are newer from some version.

I am checking if they exist, e.g.:

BEGIN { my $mod = 'File::Spec'; unless (eval "require $mod") { print "couldn't load $mod: $@"; } }
(code modified from Perl CookBook) Can I somehow check for the module version? I thought that  eval "require module version" would work. Any suggestions ?? Thank you

Comment on checking module version
Select or Download Code
Re: checking module version
by Joost (Canon) on Jun 13, 2007 at 12:23 UTC

      unless (eval "use $mod $version ()") {
      should be
      unless (eval "use $mod $version (); 1") {
      since use doesn't have a (documented) return value.

Re: checking module version
by citromatik (Curate) on Jun 13, 2007 at 12:23 UTC

    from perldoc -f use

    use Module VERSION LIST

    citromatik

Re: checking module version
by sen (Hermit) on Jun 13, 2007 at 12:40 UTC

    Hi, try this
    one-liner:
    perl -M<module> -e 'print "$<module>::VERSION"'

Re: checking module version
by andreas1234567 (Vicar) on Jun 13, 2007 at 12:46 UTC
    Take a look at Extutils::Installed and Sort::Versions.
    $ perl -wl use strict; use ExtUtils::Installed; my $instmod = ExtUtils::Installed->new(); foreach my $module ($instmod->modules()) { print $module; print $instmod->version($module); } __END__ Algorithm::Diff 1.1902 Apache::Session 1.80 Archive::Tar 1.30 Archive::Zip 1.16 Array::RefElem 1.00 ...
    --
    print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})
Re: checking module version
by ikegami (Pope) on Jun 13, 2007 at 13:50 UTC
    >perl -e "require File::Spec; File::Spec->VERSION(3.25)" File::Spec version 3.25 required--this is only version 3.12 at -e line + 1.

    VERSION is documented in UNIVERSAL.

Re: checking module version
by sago (Scribe) on Jun 14, 2007 at 10:56 UTC

    ExtUtils::Installed provides a standard way to find out
    what core and module files have been installed, and
    also the versions.

    #!/usr/local/bin/perl
    use ExtUtils::Installed;
    my $instmod = ExtUtils::Installed->new();
    foreach my $module ($instmod->modules()) {
    my $version = $instmod->version($module) || "???";
    print "$module -- $version\n";
    }
    produces the following list of modules and their version


    Apache::DBI -- 0.87
    Apache::DBILogConfig -- 0.01
    Apache::DBILogger -- 0.93
    AppConfig -- 1.52
    Archive::Tar -- 0.22
    BerkeleyDB -- 0.06
    .
    .
    .
    .
    .


    Try to execute the above program to find the modules
    that have been already installed and their versions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://620930]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-11-28 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (199 votes), past polls