Note that this is a review of the first edition of Advanced Perl Programming. It has subsequently been updated by a different author Simon Cozens in a new second edition released in I picked up Advanced Perl Programming not too long after it was first published in I bought it primarily for the chapters on XS programming, since I was just starting to develop and help maintain code that built Perl interfaces for C libraries. And then it sat on my bookshelf in the office, and then at home, until it was 16 years old.
|Published (Last):||7 June 2014|
|PDF File Size:||19.63 Mb|
|ePub File Size:||1.59 Mb|
|Price:||Free* [*Free Regsitration Required]|
Start your free trial Using References References are absolutely essential for creating complex data structures. Since the next chapter is devoted solely to this topic, we will not say more here. The only way to avoid this merger is to pass references to the input arrays or hashes.
Performance Efficiency Using references, you can efficiently pass large amounts of data to and from a subroutine. However, passing references to scalars typically turns out not to be an optimization at all. References to Anonymous Storage So far, we have created references to previously existing variables. What happens if you use parentheses instead of square brackets? The result of the expression is a scalar reference to that hash.
If you really do, you can use the following trick: Create a reference to an existing variable, and then let the variable pass out of scope. You can use the local operator instead, but there is a subtle yet very important difference between the two that we will clarify in Chapter 3.
For this example, both work equally well. This is identical to the way pointers behave in C. Dereferencing Multiple Levels of Indirection We have seen how a reference refers to some other entity, including other references which are just ordinary scalars. The following statements print the same. Incidentally, this example illustrates a convention known to Microsoft Windows programmers as " Hungarian notation.
But it is easier to check the code while you are writing it than to painstakingly exercise all the code paths during the testing phase to rule out the possibility of run-time errors. It so happens that there is a more general rule. Recall that a block can have any number of statements inside it, and the last expression evaluated inside that block represents its result value. Unless you want to be a serious contender for the Obfuscated Perl contest, avoid using blocks containing more than two expressions while using the general dereferencing rule stated above.
Trojan horses While we are talking about obfuscation, it is worth talking about a very insidious way of including executable code within strings. Moral of the story: Be very careful of strings that you get from untrusted sources. Use the taint-mode option invoke Perl as perl -T or the Safe module that comes with the Perl distribution.
Please see the Perl documentation for taint checking, and see the index for some pointers to the Safe module.
This convention is a topic of raging debates on the Internet; people either love it or hate it. In a language without enforced type checking such as Perl, I recommend using it where convenient.
Advanced Perl Programming
ADVANCED PERL PROGRAMMING SRIRAM SRINIVASAN PDF
Advanced Perl Programming by Sriram Srinivasan