2
我喜欢符号来自Exporter
驱动Perl模块使用require
而不是use
。 Perl不知道他刚输入的变量。如何使用require从导出器Perl模块导入符号?
Perl模块,样本:
package TheModule;
use strictures;
use base 'Exporter';
use Const::Fast qw(const);
const our $TEST_VAR_1 => 'Test variable 1';
our @EXPORT_OK = qw($TEST_VAR_1);
our %EXPORT_TAGS = (TEST_VAR => [qw($TEST_VAR_1)]);
Perl脚本样本
#!/usr/bin/perl
use strictures;
require TheModule;
TheModule->import(':TEST_VAR');
printf "Test variable 1 contains: %s\n", $TEST_VAR_1;
下面的例子作品,但我不得不使用require
而不是use
。
#!/usr/bin/perl
use strictures;
use TheModule (':TEST_VAR');
printf "Test variable 1 contains: %s\n", $TEST_VAR_1;
如何将require
环境中导入$TEST_VAR_1
?
不幸的是,这只是我现在已经修复的一个错字。问题依然存在。 – burnersk