This code is saved as myCalculator.pm in the directorypackage myCalculator;
---------------------------------------------
# BEGIN block
BEGIN
{
print("Welcome to myCalculator, that starts the calculations now\n\n");
}
---------------------------------------------
# END block
END
{
print("\n\nAll calculations done!\n");
}
---------------------------------------------
# Defining subroutines
sub add
{
my($x, $y) = @_;
print("$x + $y = @{[$x + $y]}\n");
}
---------------------------------------------
sub diff
{
my($x, $y) = @_;
print("$x - $y = @{[$x - $y]}\n");
}
---------------------------------------------
sub mult
{
my($x, $y) = @_;
print("$x * $y = @{[$x * $y]}\n");
}
---------------------------------------------
sub div
{
my($x, $y) = @_;
print("$x / $y = @{[$x / $y]}\n");
}
1;# return a true value to the interpreter
use myCalculator::myCalculator; # Directory_Name::Module_Name
myCalculator::add(10, 10);# invoke the subroutine 'add'
myCalculator::diff(20, 10);
myCalculator::mult(10, 3);
myCalculator::div(30, 20);
require "/home/reinier/myCalculator.pl"
add(10, 10);# invoke the subroutine 'add'
diff(20, 10);
mult(10, 3);
div(30, 20);
you'll get the file myModule.pm in the folder$ h2xs -A -X -n Template::myModule
package TEMPLATE::myModule;
---------------------------------------------
use 5.036000;
use strict;
use warnings;
---------------------------------------------require Exporter;
---------------------------------------------our @ISA = qw(Exporter);
---------------------------------------------# Items to export into callers namespace by default. Note: do not export# names by default without a very good reason. Use EXPORT_OK instead.# Do not simply export all your public functions/methods/constants.# This allows declarationuse TEMPLATE::myModule ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK# will save memory.
---------------------------------------------our %EXPORT_TAGS = ( 'all' => [ qw() ] );
---------------------------------------------our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );our @EXPORT = qw();
---------------------------------------------
our $VERSION = '0.01';
# Preloaded methods go here.
1;
---------------------------------------------
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
TEMPLATE::myModule - Perl extension for blah blah blah
=head1 SYNOPSIS
use TEMPLATE::myModule;
blah blah blah
=head1 DESCRIPTION
Stub documentation for TEMPLATE::myModule, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.
Blah blah blah.=head2 EXPORTNone by default.
=head1 SEE ALSO
Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.
If you have a mailing list set up for your module, mention it here.
If you have a web site set up for your module, mention it here.
=head1 AUTHOR
reinier, email: reinier@none.xy
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2023 by reinier
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.36.0 or,
at your option, any later version of Perl 5 you may have available.
=cut