我似乎在制作我的第一个简单包(实际上是我的第一个包)方面遇到了很多麻烦。我正在做应该做的一切(我想),但它仍然不起作用。这就是该包(我猜你可以称之为模块):
package MyModule;
use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = qw(func1 func2);
%EXPORT_TAGS = ( DEFAULT => [qw(&func1)],
Both => [qw(&func1 &func2)]);
sub func1 { return reverse @_ }
sub func2 { return map{ uc }@_ }
1;
我将这个模块保存为MyModule(是的,它被保存为.pm文件)在Perl/site/lib
中(这是我存储所有非内置模块的地方)。然后我尝试在Perl脚本中使用这个模块:
use strict;
use warnings;
my @list = qw (J u s t ~ A n o t h e r ~ P e r l ~ H a c k e r !);
use Mine::MyModule qw(&func1 &func2);
print func1(@list),"\n";
print func2(@list),"\n";
我把这个文件保存为my.pl
。然后运行my.pl
,结果出现了以下错误:
Undefined subroutine &main::func1 called at C:\myperl\examplefolder\my.pl line 7.
能有人解释一下为什么会发生这种情况吗?先谢谢了!
注意:是的,我的例子来自于Perl Monks。请参考Perl Monks "Simple Module Tutorial"。感谢tachyon!
Mine::MyModule
更改为MyModule
后问题不再有意义。 - Zaid