Perl's syntax is relatively obscure, mainly because some built-in variables and functions are handled quite exquisitely, but it is a bit difficult to understand things that are too refined. Compared with Shell, Perl is more powerful and efficient in many aspects. For example, Hash (association array) is very useful. If you want to send alarm messages sent by different hosts to different responsible persons, you need to make a lot of if or case judgments in the shell, and it is also very laborious to modify. Using associative arrays, you can easily implement this function, with concise code, convenient configuration, and one word, which is cool.
Perl supports encapsulation of code as modules. There are many useful modules on the famous CPAN, which can greatly reduce the development volume. A simple module:
package NinGoo;
require Exporter;
use strict;
use warnings;
our @ISA = qw(Exporter);
our @EXPORT = qw(fun_public); #To output the function or variable to externally call, separated by spaces
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 is generally suffixed with .pm, and the name is the same as the package, which means the name of the above Module is. Then call it in a normal . script:
#!/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. The more famous Daluo Camel "Programming Perl" has an online Chinese version here, you can check it out.
Author: NinGooSource
Perl supports encapsulation of code as modules. There are many useful modules on the famous CPAN, which can greatly reduce the development volume. A simple module:
package NinGoo;
require Exporter;
use strict;
use warnings;
our @ISA = qw(Exporter);
our @EXPORT = qw(fun_public); #To output the function or variable to externally call, separated by spaces
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 is generally suffixed with .pm, and the name is the same as the package, which means the name of the above Module is. Then call it in a normal . script:
#!/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. The more famous Daluo Camel "Programming Perl" has an online Chinese version here, you can check it out.
Author: NinGooSource