【发布时间】:2012-06-22 08:51:35
【问题描述】:
我有一个 perl 问题:导入符号,这取决于 @INC 和 use 语句中的路径元素。
如果我将完整路径放入@INC,则导入工作。如果路径的一部分在 use 语句中,则执行要导入的模块,但必须显式完成导入:
########################################
# @INC has: "D:/plu/lib/"
#------------------------------------------------
# Exporting file is here: "D:/plu/lib/impex/ex.pm"
#
use strict;
use warnings;
package ex;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT = qw( fnQuark );
sub fnQuark { print "functional quark\n"; }
print "Executing module 'ex'\n";
1;
#------------------------------------------------
# Importing file, example 1, is here: "D:/plu/lib/impex/imp.pl"
#
use strict;
use warnings;
package imp;
use impex::ex;
ex->import( @ex::EXPORT ); # removing this line makes fnQuark unavailable!
# Why is this necessary, 'ex.pm' being an Exporter?
fnQuark();
#------------------------------------------------
# Importing file, example 2, is here: "D:/plu/lib/impex/imp2.pl"
#
use strict;
use warnings;
package imp2;
use lib 'D:/plu/lib/impex';
use ex;
fnQuark(); # works without explicit import
#-------------------------------------------------
我的错误是什么?
【问题讨论】: