Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the search order in perl's include path when a module is loaded

Tags:

perl

Let's say there are three paths in @INC: path1, path2 and path3. Under each of these paths, there is a module named foo.pm. If I now load foo.pm in my script via use foo;, which of the foo.pms is actually going to be loaded? Or in other words, what is perl's search order for paths in @INC?

like image 455
Haiyuan Zhang Avatar asked Dec 02 '11 14:12

Haiyuan Zhang


1 Answers

perldoc -v %INC shows which path was chosen:

use Data::Dumper; 
print Dumper(\%INC);

Or...

perl -Mfoo -e 'print $INC{"foo.pm"}'

require shows some psuedo-code which implies the search order:

foreach $prefix (@INC) {
}

Thus, path1 would be searched first.

like image 63
toolic Avatar answered Sep 22 '22 20:09

toolic