在Perl中,当我这样做时use
,系统会.pm
在@INC
路径中的某个位置找到库的文件.
是否有可靠的方式来实际加载文件?
是的,%INC
包含从中加载模块的完整路径.
例:
$ perl -M'Data::Dump qw(pp)' -e 'pp(\%INC)' { "Data/Dump.pm" => "/usr/share/perl5/Data/Dump.pm", "Exporter.pm" => "/usr/share/perl/5.10/Exporter.pm", "List/Util.pm" => "/usr/lib/perl/5.10/List/Util.pm", "Scalar/Util.pm" => "/usr/lib/perl/5.10/Scalar/Util.pm", "XSLoader.pm" => "/usr/lib/perl/5.10/XSLoader.pm", "overload.pm" => "/usr/share/perl/5.10/overload.pm", "strict.pm" => "/usr/share/perl/5.10/strict.pm", "vars.pm" => "/usr/share/perl/5.10/vars.pm", "warnings.pm" => "/usr/share/perl/5.10/warnings.pm", "warnings/register.pm" => "/usr/share/perl/5.10/warnings/register.pm", }
如果模块具有pod文档,并且如果可以保证PATH中的perldoc实用程序属于运行脚本的相同perl,则此命令通常会为您提供实际找到的文件:
perldoc -l ModuleName
perl -M'LWP'-e'使用Data :: Dumper; 打印Dumper \%INC'| grep LWP
这将列出磁盘上的LWP模块位置,并列出LWP中加载的模块.
'LWP.pm' => '/usr/lib/perl5/5.10.0/LWP.pm', 'LWP/Protocol.pm' => '/usr/lib/perl5/5.10.0/LWP/Protocol.pm', 'LWP/UserAgent.pm' => '/usr/lib/perl5/5.10.0/LWP/UserAgent.pm',
要在查找%INC
变量,它记录了它加载您加载的库文件名do
,require
或use
.有关详细信息,请参阅perlvar.