views:

63

answers:

2

I'm using this from the command line:

perl -MDateTime::Format::DateManip -le 'print $Some::Module::VERSION'

but only return a blank line, any thoughts?

+3  A: 

It is pseudo-code, Some isn't set so it is just printing out undef with the -l flag, like perl -le'print undef;

For evidence turn on warnings with -w

$ perl -MDateTime::Format::DateManip -wle 'print $Some::Module::VERSION'
Use of uninitialized value $Some::Module::VERSION in print at -e line 1.

Substitute Some::Module with the module you want the version of.

Also, just for fun ;)

Perl Shorthands for testing version numbers

These are quick ways to get version numbers by utilizing the use <module> <version> syntax and perl's vocal rejection of versions that aren't new enough.

These are all equivalent of creating a perl script with use DateTime 9999;

$ perl -MDateTime\ 9999
DateTime version 9999 required--this is only version 0.51.
BEGIN failed--compilation aborted.

However, this fashion isn't cross-platform, because you're simply telling bash to escape a space. This doesn't work in windows cmd, for that you'll have to

$ perl -M"DateTime 9999"
DateTime version 9999 required--this is only version 0.51.
BEGIN failed--compilation aborted.

Here, you just put it in quotes - that tells cmd to send it all as an argument to perl and it gets the same job done.

Evan Carroll
Thanks, I see now: perl -MDateTime::Format::DateManip -wle 'print $DateTime::Format::DateManip::VERSION'
Phill Pafford
updated the post with a few shorthands for fun ;)
Evan Carroll
I use this bash alias to fetch version numbers: `perlversion() { perl -M$1 -wle'print $ARGV[0]->VERSION' $1 }`
Ether
+1  A: 

If you find yourself doing this frequently, you can download and install pmvers from CPAN. The script will save you from typing a potentially lengthy module name twice:

pmvers DateTime::Format::DateManip
toolic