Packages & Modules: Ex. No: 8 23/03/2011

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Priyankar Paul 1

29SCS124

Ex. No: 8
PACKAGES & MODULES
23/03/2011

Aim:
To write a PERL program to demonstrate the concept Packages & Modules.

Algorithm:
Creating and Using Perl Package

i) A PERL package is used to group associated variables and subroutines.

ii) The package key word is used to group the items.

iii) The programmer calls the subroutines by using a double colon (::). And these
subroutines can be used within other packages.

Creating and Using Perl Modules

A PERL module is simply a PERL package placed in its own file.


Priyankar Paul 2
29SCS124

Program:

Package (Arith.pm)

package Arith;

require Exporter;

@ISA=qw(Exporter);

@EXPORT_OK=qw(Hello Welcome product divide);

sub Hello

print "Hello world!\n\n";

sub Welcome

$c="Welcome to the my Programming world!\n";

return $c;

sub product

$a=$_[0];

$b=$_[1];

$c=$a*$b;

print "Product = $c\n"

sub divide

$a=$_[0];

$b=$_[1];
Priyankar Paul 3
29SCS124

$c=$a/$b;

return $c;

Program (Operations.pl)

use Arith qw(Hello Welcome product divide);

Hello;

$x=Welcome;

print "$x";

print "\nEnter 2 numbers\n";

$y=<stdin>;

$z=<stdin>;

&product($y,$z);

$ans=&divide($y,$z);

print "\nOn division, the result is $ans\n";


Priyankar Paul 4
29SCS124

Output:

Hello world!

Welcome to the my Programming world!

Enter 2 numbers
23
4
Product = 92

On division, the result is 5.75

Result:

Thus the PERL program to demonstrate the concept of Packages and Modules was
successfully executed and its output was verified.

You might also like