Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Retrieve list of used modules and their version numbers

by GrandFather (Saint)
on Sep 07, 2006 at 11:43 UTC ( [id://571662]=CUFP: print w/replies, xml ) Need Help??

The first part of the snippet goes at the top of your script.

The second part goes where you want to list the modules and versions. Sample output looks like:

Tk 804.027 Tk::Event 4.015 Tk::Event::IO 4.008 AutoLoader 5.60 DynaLoader 1.05 Tk::Submethods 4.004 Encode::Unicode 1.40
use strict; use warnings; BEGIN {our @usedModules; unshift @INC, sub {push @usedModules, [@_]; r +eturn undef;}} our @usedModules; ... my $versions = ''; for (@usedModules) { my $name = $_->[1]; $name =~ s/\..*//; $name =~ s|[\\/]|::|g; my $version = eval{eval "\$$name\::VERSION"}; $versions .= "$name \t$version\n" if defined $version; } print $versions;

Replies are listed 'Best First'.
Re: Retrieve list of used modules and their version numbers
by Fletch (Bishop) on Sep 07, 2006 at 12:39 UTC
Re: Retrieve list of used modules and their version numbers
by jmcnamara (Monsignor) on Sep 07, 2006 at 11:54 UTC

    Here is a similar one that runs from the command line.
    #!/usr/bin/perl -w use strict; for my $module (@ARGV) { my $version; eval "require $module"; if (not $@) { $version = $module->VERSION; $version = '(unknown)' if not defined $version; } else { $version = '(not installed)'; } printf " %-24s\t%s\n", $module, $version; } __END__ # Sample output. $ perl modver.pl Encode Foo strict Error::Simple Encode 2.10 Foo (not installed) strict 1.03 Error::Simple (unknown)

    --
    John.

Re: Retrieve list of used modules and their version numbers
by b10m (Vicar) on Sep 07, 2006 at 12:03 UTC

    And why not give credit to the module authors? See: Acme::Module::Authors (thanks Tatsuhiko ;-)

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Retrieve list of used modules and their version numbers
by cog (Parson) on Sep 07, 2006 at 16:05 UTC
Re: Retrieve list of used modules and their version numbers
by SankoR (Prior) on Sep 08, 2006 at 15:57 UTC
    Don't forget about perl -d:Modlist script.pl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://571662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found