开发者

What is the difference between library files and modules?

开发者 https://www.devze.com 2023-03-13 17:25 出处:网络
What is the difference betwe开发者_开发知识库en library files and modules in Perl?It\'s all Perl code to perl. All distinctions are purely idiomatic.

What is the difference betwe开发者_开发知识库en library files and modules in Perl?


It's all Perl code to perl. All distinctions are purely idiomatic.

Perl code meant for inclusion that uses a package directive:

  • 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.
    • Must therefore return a true value.
  • More modular, better supported by CPAN.

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

  • Called "library". (At least historically. These days, "library" might also be used to refer to a module or distribution.)
  • Usually has the extension .pl.
  • Should always be loaded with do.
  • Pollutes the caller's namespace.
  • Usually indicative of a substandard design. Avoid these!

Perl code meant for direct execution by interpreter:

  • 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.


Library files (I'm assuming you mean require 'foo.pl' stuff here) are an obsolete (pre-Perl 5) form of external module. For the most part, you shouldn't need to care any more, although there are still some Perl 4 installations around and therefore still some Perl code that remains backward compatible with them (and there's some code that's simply never been updated and still loads getcwd.pl etc.).


Nothing. They are both files that contain Perl code. Here are some of the possible circumstantial differences, though.

  1. A perl executable is more likely to have a #!/bin/perl shbang.
  2. Old .pl Perl libraries (hence the 'p' + 'l') are more likely to expect to be required than .pm modules.
  3. Perl 5 style (.pm) modules are more likely to use Exporter -- although even newer module eschew exporting anything.
0

精彩评论

暂无评论...
验证码 换一张
取 消