Mik*_*ike 9 perl module export
我无法理解如何将包符号导出到命名空间.我几乎完全遵循文档,但它似乎不知道任何导出符号.
mod.pm
#!/usr/bin/perl
package mod;
use strict;
use warnings;
require Exporter;
@ISA = qw(Exporter);
@EXPORT=qw($a);
our $a=(1);
1;
Run Code Online (Sandbox Code Playgroud)
test.pl
$ cat test.pl
#!/usr/bin/perl
use mod;
print($a);
Run Code Online (Sandbox Code Playgroud)
这是运行它的结果
$ ./test.pl
Global symbol "@ISA" requires explicit package name at mod.pm line 10.
Global symbol "@EXPORT" requires explicit package name at mod.pm line 11.
Compilation failed in require at ./test.pl line 3.
BEGIN failed--compilation aborted at ./test.pl line 3.
$ perl -version
This is perl, v5.8.4 built for sun4-solaris-64int
Run Code Online (Sandbox Code Playgroud)
FMc*_*FMc 15
试试这个:
package mod; # Package name same as module.
use strict;
use warnings;
use base qw(Exporter);
our @ISA = qw(Exporter); # Use our.
our @EXPORT = qw($z); # Use our. Also $a is a bad variable name
# because of its special role for sort().
our $z = 1;
1;
Run Code Online (Sandbox Code Playgroud)
其他人已正确识别问题并提供解决方案.我认为指出一个调试技巧会很有用.要将问题隔离到给定文件,您可以尝试使用perl -c(参考perlrun)编译该文件:
perl -c mod.pm
Run Code Online (Sandbox Code Playgroud)
这会给你相同的错误信息,导致你意识到问题出在你的.pm文件中,而不是你的.pl文件.
| 归档时间: |
|
| 查看次数: |
4805 次 |
| 最近记录: |