What does Perl do when two versions of a module are installed?
Asked Answered
M

2

7

I don't have root access on a remote box I'm working with, so I'm using a combination of cpanm and local::lib as described here to install CPAN modules to my local directory on the box. Using cpanm, I assume cpanm Module::To::Update would install the newest version of the module in my local library.

Apparently, I don't need root access to upgrade my modules with CPAN, as I just tried it, and the upgrade went swimmingly. However, I'm still curious which version of the module Perl will use: the local version, or the default CPAN version? Or will it just use whichever is newer?

If this exists in perldoc or Stack Overflow, I'd appreciate that as well. I tried searching both, but I wasn't able to find it =/

Mum answered 18/1, 2012 at 17:14 Comment(0)
W
13

It uses the first one it finds when searching though @INC in order.

Warta answered 18/1, 2012 at 17:15 Comment(5)
Oh. That's pretty simple. And presumably specifying use Module Version would let me pick which one I wanted manually. Thanks.Mum
@dgempesaw - That presumption would be incorrect. If you need to load a particular module from a particular place, you'll need to hack at @INC or %INC (There are lots of ways to do that. How to do that would make a good follow up question).Gripsack
@dgempesaw, To find the module's version, Perl needs to execute the module. The module can't be un-executed if it's not the right version.Marlette
@Gripsack I see. I guess I need to read the docs regarding that more closely; I understand @INC enough to put my preferred directory first.Mum
@Marlette That makes a lot of sense. Thanks.Mum
E
1

you can check it by running this in linux:

perl -e 'use <module>; print $<module>::VERSION;'

Estrous answered 1/11, 2016 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.