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
How to prevent file truncation in perl?
What are the arguements we normally use for perl interpreter?
You want to read command-line arguements with perl. How would you do that?
What are some of the key features of objects in perl?
Comment on array slicing and range operator
Explain perl. When do you use perl for programming?
How to add elements in a hash in perl?
What is perl scripting?
What does the q{ } operator do?
What is perl programming?
What $! In perl?
what is Polymorphism in Perl?
How to open a directory in perl?
What is the tk module?
What is the difference between perl array and perl hash?