Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Find perl module version from command-line

by jmcnamara (Monsignor)
on May 01, 2001 at 16:20 UTC ( [id://76927] : note . print w/replies, xml ) Need Help??

in reply to Find perl module version from command-line

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. ;-)


Replies are listed 'Best First'.
Re^2: Find perl module version from command-line
by cld (Initiate) on Jan 03, 2008 at 23:27 UTC
    When I run the perl script provided by Fastolfe I get some extra output in the results:
    dal1:/home/user1 % 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 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.


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

        I know this is kind of an old thread, but I was wondering if anyone has any code that will recursively go through a directory structure and find ALL the PERL modules and then print out the version. My Red Hat Linux distro has /usr/local/lib/perl5 and then the sub-dirs 5.8.5 and site_perl. How would I sweep through these two sub-dirs, find all the .pm files, for example, and then have it give me the VERSION if a VERSION variable exist in the .pm file? The reason I ask is I have 4 machines which I must compare VERSIONs on. So if I can get the output into 4 individual files I can easily import the data into a spreadsheet and compare. I have a small bash script that seems to work, but I'm looking for an efficient PERL method. I am just learning PERL i.e. I'm a few pages into the 5th ED. of the O'Reilly book, so the coding required is still a bit over my head, yet I have this task to complete for the boss man. Any help you can offer would be greatly appreciated.