本文介绍了库文件和模块之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Perl中的库文件和模块之间有什么区别?
What is the difference between library files and modules in Perl?
推荐答案
所有这些都是perl
的Perl代码.所有区别纯粹是习惯用法.
It's all Perl code to perl
. All distinctions are purely idiomatic.
使用package
指令包含的Perl代码:
Perl code meant for inclusion that uses a package
directive:
- 称为模块".
- 通常具有扩展名
.pm
.use
必须具有此扩展名才能找到它们. - 应该始终通过
use
. - 模块化程度更高,CPAN支持更好.
- Called "module".
- Usually have the extension
.pm
. Must have this extension foruse
to find them. - Should always be loaded with
require
, possibly viause
. - More modular, better supported by CPAN.
要包含的Perl代码不使用package
指令:
Perl code meant for inclusion that doesn't use a package
directive:
- 称为图书馆".
- 通常使用扩展名
.pl
. - 应该始终加载
do
. - 污染呼叫者的名称空间.
- 通常表示设计不合标准. 避免这些!
- Called "library".
- Usually have the extension
.pl
. - Should always be loaded with
do
. - Pollutes the caller's namespace.
- Usually indicative of a substandard design. Avoid these!
Perl代码供解释器直接执行:
Perl code meant for direct execution by interpreter:
- 称为脚本".
- 通常具有扩展名
.pl
,或者根本没有扩展名. - 可能会以shebang(
#!
)行开头,这样就可以在不指定perl
的情况下启动它们.
- Called "script".
- Usually have the extension
.pl
, or none at all. - Will probably start with a shebang (
#!
) line so they can be started without specifyingperl
.
这篇关于库文件和模块之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!