[英]Perl include file dynamically
我在perl中有一个疑问,我需要在命令行参数/开关/选项中获取文件名,因此我需要在脚本中包含/要求/使用该文件。 因此,通过使用该getopt变量能够完成它。 但是,如果我在脚本中使用了“严格使用”,则无法获取。 请帮忙
我尝试了如下及其工作
base.pm:
our $def_name = "me";
main.pl:
my $name = "mathlib.pm";
require $name;
print $def_name;
当我在main.pl和base.pm中包含以下行时,
use strict;
use warnings;
我遇到错误,
Global symbol "$def_name" requires explicit package name .
Execution of main.pl aborted due to compilation errors.
$def_name
尚未从mathlib.pm
导出,它是一个包变量,而不是全局变量。 $mathlib::def_name
将起作用,或者您可以使用Exporter
模块将其导出到使用该模块的任何模块的名称空间中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.