Advanced Perl Programming
Reviewed by Donald Bryson
Advanced Perl Programming
By Sriram Srinivasan
Available at a discount from Amazon.com on this page
Technical Level: computing -- experienced, subject -- experienced
Have you ever read a book with the uneasy feeling that the author had a hidden agenda? That's the feeling that I had with Advanced Perl Programming. Halfway through the second read it hit me -- Srinivasan is trying to trick us into being efficient.
Well, trick isn't exactly fair. He actually states in the preface, ``... it would be most gratifying, or totally tubular, as the local kids are wont to say, if the design patterns and lessons learned in this book help you even if you were to choose other languages.'' So, he does give fair warning that he is teaching methodology, not mere gee-whiz kludges.
His methodology consists of four recurring themes:
This isn't a book for casual reading. You must think about what Srinivasan is actually saying and use his advice with common sense in the context of your own goals, experience, and methodology.
It's too easy a jump from dissecting Perl to making a hypothesis about some black box. Srinivasan's methodology is not assume-and-code; Srinivasan's methodology is know-and-code. The Perl interpreter is like a glass box because the source code is freely available. Make a clear distinction in your mind between a glass box look-and-leap approach and a black box program-and-pray one.
Assumptions are always dangerous. For example, I created a C library for Xbase files several years ago. The format of the header record of a DBF file isn't a published standard. I guessed on some of the fields in the header. Some programs could read my files and others couldn't. Why? How should I know? Remember, assumptions are always dangerous.
I have reservations about looking too closely into any box -- black or glass. Contrary to my normal policy of never discussing a book review with author prior to its publication, I contacted Srinivasan for clarification of his views on interfaces and implementations. He distilled his glass box methodology via mail, which is reproduced here:
That's a reasonable methodology. It's one that mimics what we do in the physical world. However, in my opinion, examining the mechanics inside any glass box still has risks with the benefits.
For instance, His approach results in coupling, where coupling is a program's dependency on the box's implementation instead of its documentation. The Perl source code is its implementation. The lexicon of the language is its documentation. Coding based on the implementation could cause you problems with later releases of any box. For example, an algorithm might change inside the interpreter that makes your trick blowup.
Programmers generally do coupling to some degree. Would you write a script that created 1,000 temporary files in the /tmp directory? No, of course not. File system efficiency is directly related to the number of files in a particular directory. That's coupling but it's also practical.
You must temper your need for a coupling optimization with common sense. All optimizations are not the same. The trick is weighing the benefits with the risks. Compare these two examples:
There's quite a difference between cases one and two. No
problems result for case one if the next version of the compiler
creates the same output for both
This is an excellent book -- it's full of useful information, well written, beautifully set, and technically accurate. The section on Perl/Tk is especially strong. The examples are easily understood and easily modified to your own application.
It does, however, demand a lot from the reader. It requires a basic knowledge of Perl, C, and programming methods. More importantly, it requires the experience to know when and when not to use the advocated methodologies.
Advanced Perl Programming discusses three main subjects: Perl syntax, the interpreter itself, and how Perl relates to selected technologies.
This section of the book does not rehash the reference section of Larry Wall's Programming Perl book. It does, however, rehash hash of hashes. :-) True to its title, it discusses only advanced topics.
Here are a few gems from the syntax section:
The Perl Interpreter
Srinivasan discusses three topics relating to the interpreter: creating dynamically loadable C libraries to extend Perl, embedding the interpreter into a C program, and a nitty-gritty discussion of the internal workings of the interpreter.
Here are a few gems from the interpreter section:
Srinivasan discusses using various technologies with Perl. He discusses user interfaces using Perl/Tk, databases, and networks.
Srinivasan discusses databases in two chapters. He discusses various database options with Perl such as DBI and Win32::ODBC. The network section includes discussions of RPC, FTP, and POP3.