Dyn*_*mic 6 perl module packages perl-module package
制作我的第一个简单包(我实际上是我的第一个包期)似乎有很多麻烦.我正在做我应该做的一切(我想)但它仍然无法正常工作.这是包(我想你可以称之为模块):
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;
Run Code Online (Sandbox Code Playgroud)
我将此模块保存为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";
Run Code Online (Sandbox Code Playgroud)
我把它保存为my.pl.然后我运行my.pl并得到此错误:
Undefined subroutine &main::func1 called at C:\myperl\examplefolder\my.pl line 7.
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会这样吗?提前致谢!
注意:是的,我的例子来自Perl Monks.请参阅Perl Monks"简单模块教程".谢谢你快!
您的包名称和您的使用名称不匹配。如果您的模块位于名为的文件夹中Mine,那么您需要相应地命名您的包:
package Mine::MyModule
如果该文件夹中没有该文件,则需要将其从use通话中删除
use MyModule
| 归档时间: |
|
| 查看次数: |
1516 次 |
| 最近记录: |