Last Updated: February 25, 2016
·
3.127K
· ohoushyar

How to Get the Version of an Installed Perl Module?

I have been asked so many times that "How can I get the version of the module I am using?" or more general "How can I find whether I have installed the module X::X?". I know it's so easy to get this information from many channels and different ways.

My approach usually is writing a one line perl code and get my answer. Lets say I want to know the version of the module called DateTime. Here is what I would do:

~$ perl -MDateTime -E "say DateTime->VERSION;"

Lets explain a little bit more about this one line code.

-M would use the module. So it will answer whether you have it installed.

-E executes the perl code you passed. Use 5.10 or above features.

NOTE: If you don't have perl 5.10 or above installed you would get error which in that case change it to -e and use print rather than say (say is new feature of perl 5.10 and it's like print with "\n" at the end). So you would have:

~$ perl -MDateTime -e 'print DateTime->VERSION."\n";'

But here is the problem, as long as you don't use this or you don't need to get the version every single day, you would forget the command and every time you need to search it in internet or your Bible and it's going to be annoying. What I have done, I wrote a bash function and add it to my .bashrc:

perl_mod_version() { perl -M$1 -E 'say '$1'->VERSION;'; }

All you need to do is to add this to your .bashrc and reload it. You can reload your bashrc by running one of these command:

~$ . ~/.bashrc

OR

~$ source ~/.bashrc

And now you can try:

~$ perl_mod_version DateTime 

Have fun ...