A module is a Perl source file with a .pm extension. Generally modules are used as library files and can be loaded using use or require.

package is a way of providing a namespace for a section of code. The package name acts as a prefix for identifiers within the namespace. For example if a section in a Perl source file contains package Foo; followed by sub bar {} the sub can be accessed by code outside the Foo packaged as Foo::bah. Multiple sections of code may have the same package name and are treated as being all in the same namespace.

Modules generally contain a package statement with the same name used as the name of the module (excluding the .pm extension). Modules can however contain more than one package and don't need to contain any - not even a package that matches the module name.

Oh, and you can uses packages in a Perl script file (often with a .pl extension) - a package statement doesn't have to be in a module file. If no package statement is used the package name is 'main'.

True laziness is hard work

In reply to Re: difference between modules and package by GrandFather
in thread difference between modules and package by gautam_9jan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.