package Math;use strict;use warnings;use Exporter qw(import);our @EXPORT_OK = qw(add multiply); sub add {my ($x,$y) = @_;return $x + $y;}sub multiply {my ($x,$y) = @_;return $x * $y;}1;
这是调用add函数的脚本script.pl:
#!/usr/bin/perluse strict;use warnings;use Math qw(add);print add(19,23);
它给出了一个错误:
can’t locate math.pm in @INC <@INC contain: C:/perl/site/lib C:/perl/lib .> at C:\programs\script.pl line 5.
BEGIN Failed–compilation aborted at C:\programs\script.pl line 5.
如何解决这个问题呢?
解决方法 use libAdding a use lib statement to the script will add the directory to @INC for that specific script. Regardless who and in what environment runs it.
You just have to make sure to have the use lib statement before trying to load the module:
use lib '/path/to/module';use Math qw(add);
有关设置@INC的更多详细信息,请查看以下内容:
How do I include a Perl module that’s in a different directory
总结以上是内存溢出为你收集整理的在Perl中,无法在@INC错误中找到packgeName.pm全部内容,希望文章能够帮你解决在Perl中,无法在@INC错误中找到packgeName.pm所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)