gautam_9jan has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: difference between modules and package
by GrandFather (Saint) on Mar 06, 2011 at 10:23 UTC

    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
Re: difference between modules and package
by Anonymous Monk on Mar 06, 2011 at 09:23 UTC