我正在尝试学习如何使用 .pm 文件。我创建了 2 个文件:
MyScript.pl
use strict; BEGIN { unshift(@INC,"./firstdir"); } 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 seconddir::MyModule qw(func1) ; print func1(@list),"\n"; #line 21 print MyModule::func2(@list),"\n";
我的模块.pm
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;
目录结构如下:
--------------- ------------ ---------------
| firstdir ---|------> |seconddir--|-> | MyModule.pm |
| MyScript.pl | ------------ ---------------
---------------
注意: firstdir 和 seconddir 是目录,当我运行命令时,Perl MyScript.pl
我收到以下错误:
Undefined subroutine &main::func1 called at MyScript.pl line 21
你能帮我找出问题所在吗?