Chankey Pathak Chankey Pathak - 5 months ago 16
Perl Question

What is the difference between library files and modules?

What is the difference between library files and modules in Perl?

Answer

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

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

  • 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 code meant for direct execution by interpreter:

  • Called "script".
  • Usually have the extension .pl, or none at all.
  • Will probably start with a shebang (#!) line so they can be started without specifying perl.