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
Difference between the variables in which chomp function work ?
How to do comment in perl?
Explain what is lvalue?
What is perl dbi?
What is the peculiarity of returning values by subroutines in perl?
How to check the status of airplane mode (enable/disable) in perl for Android mobile?
How will you open a file in a write-only mode in perl?
What is the difference between single (') and double (") quote in a string in perl?
Remove the duplicate data from @array=(“perl”,”php”,”perl”,”asp”)
What is perl I used for?
How can memory be managed in Perl?
What does -> symbol indicates in Perl?
Explain about typeglobs?
Distinguish my and local?
Explain goto expr?