两种使用方法:
方法1:Test.pm
package Test;
use Exporter 'import';
our @EXPORT = qw (afunc $var);
sub afunc{
pirnt "This is a test.\n";
}
our $var = "CSDN";
1;
方法2:Test.pm
package Test;
use Exporter;
our @ISA = qw(Export);
our @EXPORT = qw (afunc $var);
sub afunc{
print "This is a test.\n";
}
our $var = "CSDN";
1;
调用Test.pm:
test.pl
#!/usr/bin/perl -w
use strict;
use FindBin qw ($Bin $Script);
use lib $Bin;
use Test;
afunc();
print "$var\n";