导出器模块默认导入例程的行为不符合预期

时间:2019-02-20 03:59:23

标签: perl

我有以下perl模块:

#!/usr/bin/env perl
package temp;
require Exporter;
our @ISA = ('Exporter');
our @EXPORT = qw(temp_print);
sub temp_print {
  my ($p) = @_ ;
  print "$p\n" ;
}

1;

此文件在此处:./f/temp.pm 我的主文件叫做test.pl,看起来像这样

#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw($Bin);
use lib $Bin;
use f::temp ;

temp_print("hi");

当我尝试执行test.pl时,似乎没有将temp_print导入到主包中:

% ./test.pl
Undefined subroutine &main::temp_print called at ./test.pl line 8.

我不确定我缺少什么。这似乎很基本,但是似乎无法弄清楚为什么不导入我包中的子例程。您能帮我找出问题所在吗?

1 个答案:

答案 0 :(得分:1)

use Exporter ...是速记

BEGIN {
    require Exporter;
    Exporter->import(...);
}

通过说require Exporter,您将跳过对Exporter的{​​{1}}方法的调用。

您还必须解决zdim注释所暗示的正确的程序包/文件名问题。

相关问题