My linux world » Perl – Create Perl Module (.pm)

Perl - Create Perl Module (.pm)


Contents

Perl Module

Create the following file : MyPerlModule.pm

use strict;
use warnings;
 
package MyPerlModule;
 
sub method1
{
  my $param1 = shift;
  my $param2 = shift;
  (...)
  my $paramN = shift;
 
  # Here is my method1 implémentation.
  (...)
}
 
sub method2
{
  my $param1 = shift;
  my $param2 = shift;
  (...)
  my $paramN = shift;
 
  # Here is my method1 implémentation.
  (...)
}
 
# always finish perl module with true :
1;

Use it

Import my Perl Module

require "my/relativ/path/to/MyPerlModule.pm"

Call methods

# static call :
MyPerlModule:method1(param1,param2,...,paramN);
 
MyPerlModule:method2(param1,param2,...,paramN);

Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub