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 disable the mod_perl from apache_server as i have used perlfect search on the site and its pagination is not working and the remedy is to disable the mod_perl.
How to sort arrays in perl?
What are some of the key features of objects in perl?
How to concatenate strings in perl?
Explain a tell function in perl?
What is a chomp() function in perl?
What is the use of now constructor in perl?
What do you mean by context of a subroutine?
Explain the difference between declarations of 'my' and 'local' variable scope in perl?
Explain the different types of data perl can handle.
What are scalars in perl?
What are the features of perl language?
Explain chomp, chop, cpan, tk.
Explain the meaning of subroutine?
What is perl scripting?