What is the difference between module and package?
Answer Posted / savitha sridhar
Modules and packages are usually used interchangeably. But
there is a difference.
a. Packages are perl files with .pm extn and is considered
a separate namespace. So a package is nothing but group of
related scalars,arrays,hashes and subroutines for a
specific purpose.Once a package is included in a .plx file
(using "use") and you want to call one of the subroutines
of the package, you may have to use the scope resolution
operator &package::subroutine1 ( as the subroutine of the
package is in a separate name space).
b. Modules are packages but which has the capabilities of
exporting selective subroutines/scalars/arrays/hashes of
the package to the namespace of the main package itself. So
for the interpreter these look as though the subroutines
are part of the main package itself and so there is no need
to use the scope resolution operator while calling them.
This is usually done like:
use Exporter;
our @ISA=('Exporter');
our @EXPORT=('$x','@arr',subroutine)
(you are exporting a scalar, array and a sub-routine from
the package). So if some .plx is using the above package
they need not use the scope resolution to call these.
A direct access like "print $x" would work even without
using the scope resolution.
| Is This Answer Correct ? | 22 Yes | 8 No |
Post New Answer View All Answers
What is the use of "stderr()"?
What is goto statement in perl?
What is warn function in perl?
Comment on data types and variables in perl.
Why to use perl?
What is “grep” function in perl?
how to get back up from private character editor which is saved in the format of .udf
What is 'rollback' command in perl?
How will you create a file in perl?
What rules must be followed by modules in perl.
Write an example explaining the use of symbol tables.
How will you open a file in read-only mode in perl?
What is perl pop array function?
what are the strategies followed for multiple form interaction in cgi programs?
What is cpan ? What are the modules coming under this?