3

Possible Duplicate:
How can I find the version of an installed Perl module?

I tried perl -MMODULE -e 'print Thread::Semaphore';, but it did not work! What is the right command?

Community
  • 1
  • 1
infinitloop
  • 2,863
  • 7
  • 38
  • 55

5 Answers5

8

I found something interesting I would like to share:

perl -MThread::Semaphore\ 9999 It is a neat trick to find our version!!!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
infinitloop
  • 2,863
  • 7
  • 38
  • 55
  • Wow, that's neat. You should add "-e1" to the end, just in case the module has a version higher than what you put in, otherwise it hangs. I knew about being able to use '-MThread::Semaphore=9999" and that this doesn't check VERSION, otherwise does normal importing, so a way around that is really quite helpful! :-) – Tanktalus Dec 15 '11 at 23:03
  • 1
    The fact that this line generates some output on some systems on in some shells for some installed versions of a module does not make it a correct and useful answer. – Sinan Ünür Dec 16 '11 at 13:59
  • @Tanktalus it doesn't hang, it just waits for the program to come in from STDIN. Just type Ctrl+D (on linux at least) and it will finish properly. – Brad Gilbert Dec 16 '11 at 16:38
  • `perl -e 'use Thread::Semaphore 9999'` works with all shells the same way, of course adjusting the string delimiter for windows... doesn't change the fact that a module could have a version number that high, and sadly the parser does not dwim with something like 9**9**9, since it does not look like a simple number which is what the the compiler needs to interpret it as a version requirement. And `Thread::Semaphore` itself seems to have a bug (at least in version 2.12) where it doesn't notice when you ask it to export something it does not have. So an interesting, but not foolproof method... – Eric Strom Dec 16 '11 at 23:40
  • @BradGilbert - I know. I should have put "appears to hang" if you're not expecting it. Sorry. – Tanktalus Dec 17 '11 at 05:46
5

Assuming that the module has $VERSION defined (which is where the module version is canonically stored), this will get you the version:

perl -MModule -e 'print "$Module::VERSION\n";'
a'r
  • 35,921
  • 7
  • 66
  • 67
  • Canonically, VERSION is available as a class method; the default universal method checks the VERSION variable. – ysth Dec 16 '11 at 04:05
  • Putting ysth's comment into practical code: `perl -MModule -e 'print Module->VERSION'` – daxim Dec 16 '11 at 09:02
  • More chars, but you only have to change module name once `perl -we '$_=shift; eval "use $_; 1" and print $_->VERSION' Some::Module` – Dallaylaen Dec 16 '11 at 13:16
  • `perl -MModule -e 'die Module->VERSION'` is a little shorter – Eric Strom Dec 16 '11 at 23:50
3
perl -MThread::Semaphore -le 'print $Thread::Semaphore::VERSION'
JRFerguson
  • 7,426
  • 2
  • 32
  • 36
2

You could use pm_which to find out what version a module, or a list of modules are.

$> pm_which -mV Thread::Semaphore Thread
Thread::Semaphore [ 2.12 ]
Thread [ 3.02 ]

pm_which is a front end for Module::Util, which has more methods for finding out about installed modules.

Brad Gilbert
  • 33,846
  • 11
  • 78
  • 129
0
perl -e 'eval {require Thread::Semaphore;print "Thread::Semaphore => ", $Thread::Semaphore::VERSION,"\n";}; print "\033[31mmissing Thread::Semaphore\033[0m\n";'

Here's what I had posted on Find & Checking Modules Used by Perl Programs

Pradeep
  • 3,093
  • 17
  • 21