Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Welcome to the Monastery
 
PerlMonks

Find perl module version from command-line

by lachoy (Parson)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Oct 18, 2000 at 01:15 UTC ( #37237=snippet: print w/ replies, xml ) Need Help??

Description:

How many times have you wondered what version of a module you had installed, just to check it using perl -e. Why bother? Just put this little snippet in '/usr/local/bin' or some other accessible place. (Win32 users can wrap it in a batch file.)

perlmodver Template DBI File::Spec

Results in:

Template : 2.00-beta5 DBI : 1.13 File::Spec : 0.6
#!/usr/bin/perl
use strict;
foreach my $module ( @ARGV ) {
  eval "require $module";
  printf( "%-20s: %s\n", $module, $module->VERSION ) unless ( $@ );
}
Comment on Find perl module version from command-line
Download Code
RE: Find perl module version from command-line
by Fastolfe (Vicar) on Oct 18, 2000 at 02:27 UTC
    Things like this are frequently done in conjunction with CPAN lookups. Many people don't realize that the CPAN module itself can be used in your own scripts. You can extend lachoy's example a lot further by using CPAN, at the expense of a lot of time:
    #!/usr/bin/perl use CPAN; printf("%-20s %10s %10s\n", "Module", "Installed", "CPAN"); foreach $a (@ARGV) { foreach $mod (CPAN::Shell->expand("Module", $a)){ printf("%-20s %10s %10s %s\n", $mod->id, $mod->inst_version eq "undef" || !defined($mod->inst_version) ? "-" : $mod->inst_version, $mod->cpan_version eq "undef" || !defined($mod->cpan_version) ? "-" : $mod->cpan_version, $mod->uptodate ? "" : "*" ); } }
    Running with arguments: DBI /DBD::/
    Module Installed CPAN DBI 1.13 1.14 * DBD::ADO 0.14 1.17 * DBD::ASAny - 1.09 * DBD::Adabas - 0.2003 * DBD::Altera - - * DBD::CSV - 0.1024 *
    ...etc. Though if all you're interested in is the installed version of modules, you're FAR better off going with lachoy's script, since the code above will rely upon CPAN data, which will require time to fetch, extract and browse.
RE: Find perl module version from command-line
by KM (Priest) on Oct 18, 2000 at 16:53 UTC
    This is how I do it for checking one module.. I use CPAN to check multiple:

    perl -MMODULE -e 'print $MODULE::VERSION';

    Of course, if the module author doesn't put the suggested $VERSION variable in, this won't work :)

    Cheers,
    KM

      Right! This is what I meant by perl -e in my writeup. but I thought it was getting kind of tedious to type this in every time... TMTOWDI.

Re: Find perl module version from command-line
by jmcnamara (Monsignor) on May 01, 2001 at 16:20 UTC

    I was going to post the following to the Snippets section when I came across your nicer version:
    perl -le 'eval "require $ARGV[0]" and print ${"$ARGV[0]::VERSION"} +' Module

    Your method of printing the version number is cleaner as well:
    perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Mod +ule

    I'm glad that I searched before posting. ;-)

    John.
    --

      When I run the perl script provided by Fastolfe I get some extra output in the results:
      dal1:/home/user1 % perlmodver.pl CPAN Module Installed CPAN CPAN: Storable loaded ok (v2.13) Going to read /home/user1/.cpan/Metadata Database was generated on Thu, 03 Jan 2008 05:38:06 GMT CPAN 1.9205 1.9205 dal1:/home/user1 %
      Is there a simple way to discard this additional text?

        The extra output is being generated by the CPAN module itself. I checked out the code on mine and I don't see any conditionals or anything that could be passed to supress that output. So, the simple answer is to grep for what you want or use perlmodver.pl CPAN | tail +5 because I don't think there's much you can do from the perl side that doesn't require putting more effort into it than it's worth.

        --
        naChoZ

        Therapy is expensive. Popping bubble wrap is cheap. You choose.

Back to Snippets Section

Login:
Password
remember me
What's my password?
Create A New User

Node Status?
node history
Node Type: snippet [id://37237]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (21)
Corion
GrandFather
jdporter
Your Mother
holli
Gavin
atcroft
kennethk
MidLifeXis
thezip
Eyck
pileofrogs
clinton
socketdave
metaperl
Utilitarian
ssandv
MikeDexter
smile4me
im2
plieberg
As of 2010-02-09 20:12 GMT
Sections?
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

What level of existential comfort do you require?

Palace
Executive suite at the best hotel
Regular hotel in a decent part of town
Motel
Boarding house
Sleeping Bag on Couch in Basement
Any port in a storm
Camping under the freeway overpass
Jail
Other

Results (279 votes), past polls