进行函数调用的perl编程
我想从我的程序中调用函数。因此,我可以将函数保存在另一个文件中,而不是与调用函数的脚本混合。如果是,我应该使用什么名称将文件与函数一起保存。请帮助..您可以编写模块。以下是一个小模块: 文件进行函数调用的perl编程,perl,function,Perl,Function,我想从我的程序中调用函数。因此,我可以将函数保存在另一个文件中,而不是与调用函数的脚本混合。如果是,我应该使用什么名称将文件与函数一起保存。请帮助..您可以编写模块。以下是一个小模块: 文件Foo.pm # declare a namespace package Foo; # always use these, they help you find errors use strict; use warnings; sub foo { print "Hello, this is Foo\n
Foo.pm
# declare a namespace
package Foo;
# always use these, they help you find errors
use strict; use warnings;
sub foo {
print "Hello, this is Foo\n";
}
# a true value as last statement.
1;
将该文件放置到与脚本相同的目录中:
文件script.pl
:
use strict; use warnings;
# load the module
use Foo;
Foo::foo(); # invoke the function via the fully qualified name
要创建更好的模块,您可能需要研究面向对象,或者
导出器模块。文件名根本不重要。