facebook twitter youtube
in perl - 15 Jun, 2011, This Tutorial Has Been Viewed 3,117 Times.
by admin - no comments
Simple Perl Module Script
VN:F [1.9.22_1171]
Rating: 4.5/10 (2 votes cast)

This tutorial is just an introduction to perl module.Here you will find a very simple approach of module creation.
Each module contains a package declaration–usually as the first statement of the file–and this package declaration must match the name of the file itself (the file will additionally have a “.pm” extension; so, in our example above, the module would reside in a file called “MyFirstModule.pm”)

package MyFirstModule;

sub hello_message {
return "Hello Visitors!";
}
1;

Your module must return a true value (or a value synonymous with true) so that Perl knows that it was loaded properly when it is used. This will often be the case without having to do anything special; as many Perl commands will return a value that will be interpreted as true anyway; but to be sure of it we use a common module coding trick: We include, as the last statement of the module, a single “command:”

1;
Perl interprets this expression and of course returns true since 1 is always interpreted as a true value.

Having defined our simple module, let’s have a look at a script that makes use of it:

#!/usr/bin/perl
use MyFirstModule;
print MyFirstModule::hello_message()."\n";

VN:F [1.9.22_1171]
Rating: 4.5/10 (2 votes cast)
Simple Perl Module Script, 4.5 out of 10 based on 2 ratings

Incoming search terms:




coded by nessus

Leave a Reply

Close
Please support the site
By clicking any of these buttons you help our site to get better