库文件和模块有什么区别? [英] What is the difference between library files and modules?

查看:45
本文介绍了库文件和模块有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 找到它们.
  • 应该总是加载require,可能通过use.
  • 更加模块化,CPAN 更好地支持.
  • Called "module".
  • Usually has the extension .pm. Must have this extension for use to find them.
  • Should always be loaded with require, possibly via use.
  • More modular, better supported by CPAN.

不使用 package 指令的 Perl 代码:

Perl code meant for inclusion that doesn't use a package directive:

  • 称为图书馆".(至少在历史上是这样.如今,库"也可能用于指代模块或发行版.)
  • 通常具有扩展名 .pl.
  • 应始终加载do.
  • 污染调用者的命名空间.
  • 通常表示设计不合标准.避免这些!

用于解释器直接执行的 Perl 代码:

Perl code meant for direct execution by interpreter:

  • 称为脚本".
  • 通常有扩展名 .pl,或者根本没有.
  • 可能会以shebang (#!) 行开头,这样它们就可以在不指定perl 的情况下启动.
  • Called "script".
  • Usually has the extension .pl, or none at all.
  • Will probably start with a shebang (#!) line so they can be started without specifying perl.

这篇关于库文件和模块有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆