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
- Perl Tutorial - Learn Perl With Examples
- Perl | Basic Syntax of a Perl Program
- ES6 | Modules
- AngularJS | Modules
- Node.js | Modules
- How to Create Modules in Node.js ?
- How to use External Modules and NPM in a project ?
- How to remove all Global Modules in Node.js ?
- How to use font-awesome icons from node-modules?
- Perl vs C/C++
- Perl Hash
- Perl | last in loop
- Formats in Perl
- Perl | GET vs POST in CGI
- Perl | int() function
- Perl | each() Function
- Perl | uc() Function
- Perl | ge operator
- Perl | eq operator
- Perl | q 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 email@example.com. 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.