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 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 Fletch (Bishop) on Sep 07, 2006 at 12:39 UTC
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