2010-05-18 70 views

回答

10
# In Foo.pm. 
package Foo; 

use strict; 
use warnings; 

use base qw(Exporter); 
our @EXPORT = qw(bar); 

sub bar { print "bar(@_)\n" } 

1; 

# In your script. 
use strict; 
use warnings; 

require Foo; 
Foo->import('bar'); 
bar(1, 22, 333); 
+0

'package'聲明到頂部。 – daxim 2010-05-18 15:55:51

3

最簡單的方法可能是使用像Module::Load模塊:

use Module::Load; 
load Data::Dumper; 
+0

鏈接已損壞。嘗試http://search.cpan.org/~bingos/Module-Load-0.32/lib/Module/Load.pm,或者甚至是http://perldoc.perl.org/Module/Load.html。 – 2016-01-18 20:13:08