我有一个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 …Run Code Online (Sandbox Code Playgroud) 有时候我想写:
my $var = shift // undef; # argument is optional
# or
my $var = $val{optional_value} // undef;
Run Code Online (Sandbox Code Playgroud)
表示可以缺少参数,否则// undef当然没用.
这有多贵,它是否被编译器优化了?