我在同一个文件夹中创建了两个文件来学习模块。
Modules.pm
package Modules;
use strict;
use warnings;
require Exporter;
BEGIN { our @EXPORT = qw(Print); }
sub Print { print shift(@_); }
END { }
1;
Main.pl
use strict;
use warnings;
use Modules;
Print("Hello World!");
运行命令perl Main.pl我收到以下错误。我做错了什么?
Undefined subroutine &main::Print called at Main.pl line 7
答案 0 :(得分:4)
您忘了告诉您的软件包它继承自Exporter
package Modules;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(Print);
sub Print { print shift(@_); }
1;
或更不容易出错,
package Modules;
use strict;
use warnings;
use parent qw( Exporter );
our @EXPORT = qw(Print);
sub Print { print shift(@_); }
1;
中的更多内容