Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
730 views
Welcome To Ask or Share your Answers For Others

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

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...