Wednesday, December 9, 2009

How to create Perl Packages/Modules?

Create a file called cc.pm where the package/module name is cc. Copy the below code. I have created my own print function called myprint and going to call this function from some other script.

[murugaia@build1] ~> cat cc.pm
package cc;
sub myprint
{
my $Element = pop(@_);
print("Hai $Element\n");
};
1;

Create another script which will call package cc and its functions. Here myprint function has been called from package cc.

[murugaia@blrmimsbuild1] ~> cat cc.pl
#! /usr/bin/perl
use cc;
$print=cc::myprint("Sathiyseelan");
print("$print");

[murugaia@build1] ~>
[murugaia@build1] ~>



No comments:

Post a Comment