In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the Perl module, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Perl module
Most large programs are divided into multiple parts, each of which usually contains one or more subroutines and related variables to perform specific one or more tasks. Components that collect variables and subroutines are called program Perl modules.
1. Create a Perl module
The Perl module is created with packages in Perl5 by creating the package and storing it in a file with the same name. For example, a package named Mymodult is stored in the file Mymodult.pm (the extension .pm stands for PerlModule). The Perl module Mymodult in the following example contains subroutines myfunc1 and myfunc2 and variables $myvar1 and $myvar2.
1 myvar1 myvar2; 8: 9:submyfunc1 {10 myfunc1myfunc2; 11:} 12: 13:submyfunc2 {14: 14; myvar2; 15:}
Lines 3-7 are the standard way of defining PerlPerl modules. Line 3 defines the package, and line 4 contains the built-in PerlPerl module Exporter,6, 7-line subroutines, and the output of variables to communicate with the outside world. Line 6 creates a special array called @ EXPORT, in which subroutines can be called by other programs, where myfunc1 and myfunc2 can be accessed. Any other subroutines defined in the Perl module but not assigned to the array @ EXPORT are private and can only be called within the Perl module. Line 7 creates another special array called @ EXPORT_OK that contains variables that can be accessed by external programs, including $myvar1 and $myvar2.
2. Import Perl module
Import the Perl module into your Perl program using the use statement, such as the following sentence to import the MymodulePerl module:
UseMymodule
In this way, the subroutines and variables in the Perl module Mymodule can be used.
Cancel importing the Perl module using the no statement, such as the following sentence cancels the import of the MymodulePerl module:
NoMymodule
Let's take a look at an example of importing the Perl module and canceling the import. Using the integerPerl module requires all numeric operations to be based on integers, and floating-point numbers are converted to integers before the operation.
1VERVERGUTHERMAX localBINGUBING Perl 2: 3 VOLTERBINGER; 4VOLINGER 2.4mm 2.4; 5:print ("$result\ n"); 6: 7VOINTER; 8RUBRETHER 2.4 times 2.4; 9:print ("$result\ n")
The program output is as follows:
$program
four
4.8
$
If a use or no statement appears in a statement block, it only works within the valid scope of that block, such as:
Useinteger; $result1=2.4+2.4; if ($result1==4) {nointeger; $result2=3.4+3.4;} $result3=4.4+4.4
The output is as follows:
four
6.8
eight
Here, the no statement is only valid in the if statement, and the integerPerl module is still used in the if statement, so 4. 4 is converted to 4 before adding.
3. Predefined Perl module
Perl5 provides many useful predefined Perl modules that can be cancelled with use imports and no statements. Here are some of the most useful Perl modules in the library:
There is a complete list of predefined Perl modules in the Perl documentation.
Note: Perl5 users around the world have written many useful Perl modules, and the CPAN (ComprehensivePerlArchiveNetwork) Perl document has a complete list.
Thank you for reading this article carefully. I hope the article "how to use the Perl Module" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.