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 | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- How to remove all Global Modules in Node.js ?
- AngularJS | Modules
- ES6 | Modules
- How to use External Modules and NPM in a project ?
- How to Create Modules in Node.js ?
- Node.js | Modules
- How to use font-awesome icons from node-modules?
- Perl | split() Function
- Perl | chomp() Function
- Perl | Backtracking in Regular Expression
- Perl | Searching in a File using regex
- Perl | Operators | Set - 1
- Perl | lt operator
- Perl | chop() Function
- Perl | rename() Function
- Perl | Subroutines or Functions
- Perl | Decision Making (if, if-else, Nested–if, if-elsif ladder, unless, unless-else, unless-elsif)
- Perl | Scalars
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.