In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the content of a sample analysis of Perl classes and creation methods. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Perl class
A brief introduction to the module
The module is the Perl package (pachage). Objects in Perl are based on references to data items in the package. (for references, see Chapter x references).
See http://www.metronet.com 's perlmod and perlobj for details.
When using other languages for object-oriented programming, first declare a Perl class and then create an object (instance) of the Perl class. All objects of a particular Perl class behave in the same way, determined by the Perl class method. You can create a Perl class by defining a new Perl class or inheriting from an existing Perl class. People who are already familiar with object-oriented programming can encounter many familiar terms here. Perl has always been an object-oriented language, and in Perl5, the syntax has changed slightly to standardize the use of objects.
The following three definitions are critical to understanding how objects, Perl classes, and methods work in Perl.
The ◆ Perl class is a Perl package that contains a Perl class that provides object methods.
The ◆ method is a Perl subroutine, and the Perl class name is its * * parameters.
The ◆ object is a reference to a data item in the Perl class.
2. Perl class in Perl
Again, a Perl class is just a package. When you see a reference to the "Perl class" in the Perl document, just think of it as a "package". The syntax of Perl5 can create Perl classes, and if you are already familiar with Clippers, you have mastered most of the syntax. Unlike Perl4, the concept is to use a double colon (::) to identify the basic Perl class and the inherited Perl class (child Perl class).
An important feature of object-oriented is inheritance. The inheritance feature in Perl is not exactly the same as other object-oriented languages, it only inherits methods, you must use your own mechanism to achieve data inheritance.
Because each Perl class is a package, it has its own namespace and its own associative array of symbolic names (see Chapter x associative array for details), so each Perl class can use its own set of symbolic names. In conjunction with package references, you can use the single quote (') operator to locate variables in the Perl class, such as: $class'$member for members in the Perl class. In Perl5, you can use double colons instead of single quotation marks to get references, such as: $class'$member is the same as $class::$member.
Third, create the Perl class
This section describes the necessary steps to create a new Perl class. The following example is to create a simple Perl class called Cocoa, whose function is to output the necessary part of the source code for a simple Java application. Rest assured, this example does not require you to have knowledge of Java, but it does not make you a Java expert, and its purpose is to describe the concept of creating Perl classes.
First, create a package file named Cocoa.pm (the extension pm is the default extension of the package, meaning PerlModule). A module is a package, and a package is a Perl class. Add the line "1;" before doing anything else, and when you add other lines, remember to keep "1;" as a line. This is a necessary condition for the Perl package, otherwise the package will not be processed by Perl. The following is the basic structure of the file.
PackageCocoa; # # Put "require" statementsinforallrequired,importedpackages # Justaddcodehere # 1 position terminatethepackagewiththerequired1
Next, we add a method to the package to make it a Perl class. The * method to be added is new (), which must be called when the object is created, and the new () method is the constructor of the object.
Thank you for reading! This is the end of this article on "sample analysis of Perl classes and creation methods". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.