Perl Module Writing Instructions _ Application Tips

Source: Internet
Author: User
Perl's syntax is relatively obscure, mainly because some of the built-in variables and functions are handled fairly finely, and the overly refined stuff is a bit laborious to understand. Relative to the Shell,perl in many ways more powerful and efficient, such as hash (associative array) is very useful, if you want to send the alarm message from different hosts to the different responsible person, in the shell to do a lot of if or case judgments, modified also very laborious, and use associative array , you can easily achieve this function, code concise, convenient configuration, a word, cool.

Perl supports encapsulation of code with modules. The famous cpan has a lot of useful module, can greatly reduce the amount of development. A simple module:

Package Ningoo;
Require exporter;
Use strict;
Use warnings;

Our @ISA = QW (exporter);
Our @EXPORT = QW (fun_public); #要输出给外部调用的函数或者变量, separated by a space
Our @version = 1.0;
Sub func_private{
Print "This is a private function";
}

Sub func_public{
print "hello,world\n";
Func_private ();
}

1;
__end__
The file name of the module usually has a. PM suffix, the name and package the same, that is, the name of this module is ningoo.pm. And then in the normal. Script, call:

#!/usr/bin/perl-w
# Creator:ningoo
# function:test Perl module

BEGIN {
Push (@INC, '/home/module ');
}

Use strict;
Use Ningoo;

Func_public ();
O ' Relly published a series of Perl books, and the more famous camel "programming Perl" here has an online Chinese version that can be seen.
Author: Ningoo Source
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.