【发布时间】:2014-07-18 03:49:57
【问题描述】:
我正在尝试从 Perl 模块导入一个变量。我注意到当变量名的长度为一个字符时它起作用,而当它的长度大于一个字符时它不起作用。我现在什至无法做到。
我知道你可以用 Perl gotcha 的列表填满一个小体育场,但这很奇怪。为什么会这样?
示例 1)
mod.pm
use strict;
use warnings;
our $aa = 1;
1;
test.pl
#!/usr/bin/perl
use warnings;
use strict;
use mod;
print $aa . "\n";
运行它。失败了
$ ./test.pl
Variable "$aa" is not imported at ./test.pl line 8.
Global symbol "$aa" requires explicit package name at ./test.pl line 8.
Execution of ./test.pl aborted due to compilation errors.
示例 2)
mod.pm
use strict;
use warnings;
our $a = 1;
1;
test.pl
#!/usr/bin/perl
use warnings;
use strict;
use mod;
print $a . "\n";
运行它。它通过了
./test.pl
1
还有我的解释器的版本信息
$perl -v
This is perl 5, version 16, subversion 2 (v5.16.2) built for darwin-thread-multi-2level
【问题讨论】:
标签: perl