[root@node01 lib]# cat Pk01.pm
package Pk01;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(munge frobnicate); # symbols to export on request
sub munge{
my $a=shift;
my $b=shift;
return $a+$b;
};
sub frobnicate{
my $a=shift;
my $b=shift;
return $a*$b;
};
1;
[root@node01 lib]# cat a1.pl
use Pk01 qw(munge frobnicate);
print munge(22,33);
print "\n";
print frobnicate(22,33);
print "\n";
[root@node01 lib]# perl a1.pl
55
726
此時都正常輸出:
[root@node01 lib]# cat a1.pl
use Pk01;
print munge(22,33);
print "\n";
print frobnicate(22,33);
print "\n";
[root@node01 lib]# perl a1.pl
Undefined subroutine &main::munge called at a1.pl line 2.
這個導緻Perl來加載你的子產品 但是不導入任何符号表
[root@node01 lib]# cat Pk01.pm
package Pk01;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(munge frobnicate); # symbols to export on request
sub munge{
my $a=shift;
my $b=shift;
return $a+$b;
};
sub frobnicate{
my $a=shift;
my $b=shift;
return $a*$b;
};
1;
[root@node01 lib]# cat a1.pl
use Pk01;
print munge(22,33);
print "\n";
print frobnicate(22,33);
print "\n";
[root@node01 lib]# perl a1.pl
55
726
@EXPORT 這個導入所有的符号從YourModule's @EXPORT 到你的名字空間