Marek Rouchal wrote to me with an interesting addendum to my previous post Who makes it into @INC first?. Besides the different ways to add directories, some of them also load additional subdirectories that you don’t specify.
Perl finds modules by looking through the list of directories in
@INC. There are many ways to add paths to that array, and although I’ve used all of them at some point, I’ve never quite thought about what happens when I use all of them together.
Remember that Perl uses the first matching module name it finds then
stops looking. It does not have a designed way to determine a best match and newest match or anything fancy. Whatever it finds first is the winner. This also means that someone could add paths to
@INC and force your program to run their version of a module, even maliciously. This is something I write about in the “Secure Programming Techniques” chapter of Mastering Perl.