使用模块。查看
perldoc perlmod和
Exporter。
在文件Foo.pm
package Foo;
use strict;
use warnings;
use Exporter;
our @ISA= qw( Exporter );
# these CAN be exported.
our @EXPORT_OK = qw( export_me export_me_too );
# these are exported by default.
our @EXPORT = qw( export_me );
sub export_me {
# stuff
}
sub export_me_too {
# stuff
}
1;
在您的主程序中:
use strict;
use warnings;
use Foo; # import default list of items.
export_me( 1 );
或获得两个功能:
use strict;
use warnings;
use Foo qw( export_me export_me_too ); # import listed items
export_me( 1 );
export_me_too( 1 );
您也可以导入包变量,但是强烈不建议这样做。