With more than examples, Perl Black Book, 2nd Edition is a complete reference to the Perl language ranging from language syntax and idioms to its use in. Perl Black Book: The Most Comprehensive Perl Reference Available Today Paperback – August 14, Steven Holzner (Cambridge, MA) is a former contributing editor for PC Magazine and has authored more than 60 books ranging in subject from assembly language to C++. Perl Black Book book. Read reviews from world's largest community for readers. Written by Steve Holzner, former contributing editor for PC Magazine and t.
|Language:||English, Spanish, Arabic|
|Genre:||Children & Youth|
|Distribution:||Free* [*Registration needed]|
The inheritance feature offered by Perl, however, is not the same as you might expect from other object-oriented languages. Perl classes inherit methods only; you must use your own mechanisms to implement data inheritance. Because each class is a package, it has its own name space with its own associative array of symbol names. Each class can therefore use its own independent set of symbol names. As with package references, you can address the variables in a class with the back quote ' operator.
In Perl 5, you can use the double colon instead of the ' to get the reference.
Creating a Class This section covers the requisite steps to take when you create a new class. The example illustrates the semantics in the creation of a simple class called Cocoa, which is used for printing the required parts of a source code file for a simple Java application.
You will not become a Java expert, nor will this package require you to have any experience in Java; the focus is the concept of creating a class.
The example could have just as easily used a phone book application, but how many similar examples have you already seen in books? It's named Cocoa.
Perhaps after reading today's lesson you will be able to contribute to the Java. Time now for a shameless plug for Perl Unleashed, which is also by Sams Publishing, due the summer of It will contain gobs of information about writing and using classes and packages-and track the initial development stages of the Java.
Maybe the package should be called Bean. First of all, create a package file called Cocoa. A module is a package, and a package is a class for all practical purposes. Before you do anything else, place a 1; in the file. As you add more lines to the package file, make sure you keep the 1; as the last line. The following code shows the basic structure of the file: package Cocoa; Put "require" statements in for all required,imported packages Just add code here 1; terminate the package with the required 1; This requirement is important: Don't forget to always keep the 1; line as the last of the package file.
This statement is required for all packages in Perl. If you forget this statement, your package will not be processed by Perl. Congratulations; you have just created your first package file. Now you are ready to add your methods to this package and make it a class.
The first method you should add is the new method, which must be called whenever you create a new object. The new method is the constructor for the object. Blessing a Constructor A constructor is a Perl subroutine in a class that returns a reference to something that has the class name attached to it.
Connecting a class name with a reference is referred to as "blessing" an object because the function to establish the connection is called bless.
The following code segment shows the syntax for the bless function: bless YeReference [,classname] YeReference is the reference to the object being blessed. The classname is optional and specifies the name of the package from which the object will get methods.
If the classname is not specified, the name of the current package is used instead. The way to create a constructor in Perl is to return a reference to an internal structure that has been blessed into this Cocoa class.
Listing The initial Cocoa. The returned value to the calling function now refers to this anonymous hash. Therefore, the reference count to the hash won't be zero and Perl keeps the hash in memory. You do not have to keep it around, but it's nice to have it around for reference later. Creating the constructor. In line 2, the local directory is added to the search path in INC for the list of paths to use when looking for a package. You can create your module in a different directory and specify the path explicitly there.
The use statement is required if you want to work with a class. Line 4 creates the Cocoa object by calling the new function on it. Now comes the beauty and confusion and power of Perl. There is more than one way to do this. For the Cocoa.
You might want to use the constructor to initialize variables or set up arrays or pointers specific to the module. DO initialize variables in your module in the constructor.
DO use the my construct to create variables in a method. DON'T use the local construct in a method unless you really do want the variables to be passed down to other subroutines. DON'T use global variables in the class module. TIP When you are working with instance variables, it is sometimes easy to visualize a Perl object as simply an associative array.
Then it's easy to see that each index in the associative array is a member of that class and each item at the index of the associative array is a value of that member. Revised constructor for Cocoa. Now you've created some comments at the beginning of a file with some print statements. You can just as easily call other functions in or outside of the package to get more initialization functionality. You should be able to call the new operator with the class name as the first parameter.
This capability to parse the class name from the first argument causes the class to be inherited.
The following code uses the function call ref to determine if the class exists per se. The ref function returns true if the item passed to it is a reference and null if it is not a reference.
With classes, the true value returned from the ref function is the name of the class. Outside the class package, the reference is generally treated as an opaque value that can only be accessed through the class's methods. You can access the values within the package directly, but it's not a good idea to do so because such access defeats the whole purpose of object orientation. It's possible to bless a reference object more than once.
However, the caveat is that the new class must get rid of the object at the previously blessed reference. For C and Pascal programmers, this is like assigning a pointer to malloced memory and then assigning the same pointer to another location without first freeing the previous location. In effect, a Perl object must belong to only one class at a time. If you are a seller for this product, would you like to suggest updates through seller support?
Read more Read less. Save Extra with 2 offers. Customers who viewed this item also viewed. Page 1 of 1 Start over Page 1 of 1. Perl by Example.
Ellie Quigley. About the Author Steven Holzner - is an award-winning author who not only writes about Perl, but also uses it daily in Web Development. To get the free app, enter mobile phone number. See all free Kindle reading apps.
Tell the Publisher! I'd like to read this book on Kindle Don't have a Kindle? Product details Paperback Publisher: Dreamtech Press; Second edition 18 December Language: English ISBN Share your thoughts with other customers. Write a product review. Showing of 2 reviews. Top Reviews Most recent Top Reviews.
There was a problem filtering reviews right now. Please try again later. Verified download.
The Book I recieved is of very bad quality, the binding is folded diagonally, because of some misplacement by the customer. Since, thats not going to affect the contents of books. See both reviews. Most helpful customer reviews on site. Everyone else has pretty much summed up the pluses of this book. I'd just like to add that when it has come to very specific questions and problems I've had with a Perl script like interprocess communication , the only book that has always answered my questions is the Perl Black Book.
You'll be amazed at the topics covered and at the depths they are covered.