A module in Perl is a collection of related subroutines and variables that perform a set of programming tasks. Perl Modules are reusable. Various Perl modules are available on the Comprehensive Perl Archive Network (CPAN). These modules cover a wide range of categories such as network, CGI, XML processing, databases interfacing, etc.
A modules name must be same as to the name of the Package and should end with .pm extension.
Example : Calculator.pm
Here, the name of the file is “Calculator.pm” stored in the directory Calculator. Notice that 1; is written at the end of the code to return a true value to the interpreter. Perl accepts anything which is true instead of 1
To import this calculator module, we use require or use functions. To access a function or a variable from a module, :: is used. Here is an example demonstrating the same:
Variables from different packages can be used by declaring them before using. Following example demonstrates this
Perl file to access the module is as below
Perl provides various pre-defined modules which can be used in the Perl programs anytime.
Such as: ‘strict’, ‘warnings’, etc.
Hello This program uses Pre-defined Modules
- ES6 | Modules
- AngularJS | Modules
- Perl | Basic Syntax of a Perl Program
- Perl vs C/C++
- Perl | next operator
- Perl | References
- Perl | sin() Function
- Perl | log() Function
- Perl | given-when Statement
- Use of print() and say() in Perl
- Perl vs Python
- Perl | cos() Function
- Perl | oct() Function
- Perl | exp Function
- Perl | cmp Operator
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.