Core Perl: A Book Review
Title: Core PerlAuthor: Reuven M. LernerPublisher: Prentice-Hall, Inc.URL: www.coreperl.comISBN: 0-13-035181-4Price: US$44.99
Every Linux Journal reader is probably familiar with Reuven Lerner's "At The Forge" column, where each month he describes web programming techniques and technologies. If you are a fan of Perl (like me), you probably mourned Reuven's recent shift to Java as the programming language around which he structures his discussions. The monthly Perl-fix in LJ has been missing for some time now, and Java appears to be everywhere. What kept me going was Reuven's standard signature sign-off teasing that his book, Core Perl, was to be published "real soon now" by Prentice-Hall. The book finally published in January 2002, and, as I'm always on the lookout for a good all-around Perl text to recommend to my students, I was keen to take a look at it.
Core Perl is part of the Prentice-Hall PTR Core Series, a set of programming books aimed at the professional programmer. The Core Series is most closely associated with Core Java by Horstmann & Cornell. Although primarily a Java-focused collection, a small selection of Core Series books cover other programming technologies, namely Python, C++, PHP and now Perl. Tagged as the Serious Developer's Guide to Perl, Reuven's book is positioning itself not as a book for newbie programmers, but as a book for already practicing Perl programmers or for programmers of another language who want to learn Perl.
Overall, Reuven does a pretty good job of meeting the needs of these two audiences. In it's 565 pages, Core Perl includes some 18 chapters, each devoted to a specific Perl topic. In the preface, the structure of the book is presented, together with a list of Perl topics not covered by the book. These topics would be considered advanced Perl technologies, and they include GUI-development (using Tk), linking to C/C++, using XS, compilation and threads programming. If you are interested in these Perl topics, you will need to look elsewhere. The rest of the book can be roughly split into three main sections (although they aren't identified as such in the text): Perl as a programming language (chapters 1 through 10, and chapter 13), working with databases (chapters 11 through 12) and working with the web (chapters 14 through 18).
After describing what Perl is, what it isn't and how to get it in Chapter 1 ("What is Perl?"), things really get going in Chapter 2 ("Getting Started"), and the reader is introduced to the basic variable building blocks of Perl--scalars, arrays, lists, hashes and references. As this is a book aimed at practicing programmers, I was surprised to see descriptions of what HEX and OCTAL numbers are and how they work. Can there be a programmer out there that doesn't know what a HEX number is?! Of more interest (and importance) is the coverage of the way scoping works in Perl at the end of this chapter, where the differences between global and lexical variables are described. In Chapter 3 ("Extending your Perl Vocabulary"), coverage of the syntax of the language continues. This material includes basic I/O, the conditional constructs, operators and loops. A number of the more heavily used built-in functions are also described. The fork and eval functions are briefly described at the end of this chapter. I didn't really like the accompanying descriptions and would have preferred some additional, expanded discussion and review of these important functions.
Chapter 4 ("Subroutines"), is all about, well, subroutines. The discussion about signals toward the end of the chapter would have benefitted from providing a list of signals that Perl does and doesn't support. However, in general, this material is fine. Chapter 5 ("Text Patterns") is a good tutorial on Perl's regular expression, pattern-matching technology. Chapter 6 ("Modules") continues discussing the mechanics of Perl programs, describing the creation of namespaces with the package command. The steps required to create a standalone module file are also discussed. The latter half of this chapter presents a brief collection of some of the third-party add-on modules available for Perl from the CPAN repository. The creation of documentation using POD is also covered. Following the chapter on modules, Chapter 7 ("Objects") discusses using Perl as an object-oriented programming technology. Although the material presented is fine, I found the examples to be somewhat simplified. If I was moving to Perl from another OO language and reading this book, I'd be asking myself "is that it?". This chapter was also far too short, but what's there is good.
Reuven redeems himself somewhat in the next chapter, "Tying". The tie and untie subroutines are presented, together with a really excellent description of how to tie variables of differing types to scalars, hashes, DBM files and arrays. I have always struggled a little with tying in Perl, but by the time I had finished this chapter I was saying to myself "now I get it!".
Chapter 9 ("Working with Files"), returns to the topic of performing I/O with Perl. One of the largest chapters in the book, this material details how to work with files, directories, and the underlying operating system from within your Perl programs. As expected, this material is presented very much from the perspective of the Perl programmer working with UNIX or Linux. Chapter 10 ("Networking and Interprocess Communication"), is another large chapter. Here the techniques required to program anonymous and named pipes are described, together with an introduction to network programming with the Socket API. In the first half of this chapter, a small collection of clients and a server are presented. The discussion of this material is marred by some pretty poor descriptions of what is going on. Coupled with some incorrect comments in the program code, the result is disappointing coverage of this material. The second half of the chapter describes a collection of Internet add-on modules available for Perl. Example protocols programmed include FTP, Telnet, SMTP (e-mail) and HTTP (the web). HTML parsing is also briefly described.
Having disappointed in the last chapter, Reuven again redeems himself with another great chapter. Chapter 11 ("Relational Databases") is about as good an introduction to databases and SQL as you are likely to find in a book of this kind. I really liked this material, even though I tend to find the subject of databases to be pretty dull stuff. The standardized Perl API to databases (DBI) is also introduced in this chapter. Note that the RDBMS used by Reuven is the open-sourced PostgreSQL. Chapter 12 ("Building Database Applications") expands upon the previous chapter and builds a complete database application using Perl, DBI and PostgreSQL. Additional material covers debugging DBI. Again, I found the material in this chapter to be very good and well presented.
Chapter 13 ("Maintenance and Security") serves as a separator between the database section of the book and the web section, and it includes an overview of the help Perl gives to the programmer when dealing with warnings and errors. Debugging is also covered (both command-line and graphical), as is benchmarking and tainting (Perl's paranoid mode). Providing only a two-page description of tainting was, in my opinion, not enough coverage (especially in light of the book's next chapter, which introduces CGI).
The final four chapters of the book (together with the database chapters) have the most to offer practicing Perl programmers. After a lightening fast introduction to HTTP, HTML and URLs, a brief tour of Perl's support for CGI is presented in Chapter 14 ("CGI Programming"). Apache is the host web server for the CGIs presented in this chapter. I would have liked to have seen some screenshots in this (and the subsequent) chapter(s), as I believe they would have enhanced the discussion and explanation of the CGI programs presented. Chapter 15 ("Advanced CGI Programming") expands on the introduction in Chapter 14 and presents more complete CGI example programs. These include setting-up a registration system, programming cookies, dynamically creating images and the basics of working with HTML templating technology. The examples are good, but, some screenshots would have made them better.
Chapter 16 ("Web/Database Applications"), combines the database techniques from Chapters 11 and 12 with the CGI techniques from Chapters 14 and 15. This is another great chapter (although it too suffers somewhat from a lack of screenshots), and it contains some quite long and involved programming examples. These examples include working with stock data stored in a web-hosted database, a web-based electronic postcard sending system and personalization technologies that combine a web-hosted database with cookies.
The final two chapters of the book are targeted at heavy-weight web programmers. Chapter 17 ("mod_perl") discusses the popular Perl add-on module to Apache. Coverage includes installation, configuration and use of the mod_perl module. Three simple handlers are presented in order to demonstrate the basic mechanism, then the latter half of the chapter presents a collection of standard mod_perl modules (including Apache::DBI for connecting mod_perl handlers to a back-end database). The final chapter of the book, titled "Mason", presents a more detailed description of HTML templating technology. This is a good, introductory description of HTML::Mason. I tend not to do much dynamic web page development; however, if you spend any portion of your day creating web sites with HTML and Perl, this technology looks like something you really should be into. The single appendix (Bibliography and Recommended Reading) presents Reuven's recommended reading-list. This is a nice, small collection of some of the most important works in this area. A detailed 33-page index completes the book.
The best advice I could give any programmer reading Core Perl would be to work through the book with your computer and Perl be your side. To get the most from any programming book, you need to try out the examples to solidify your understanding of the topic being discussed. This is especially true of Core Perl. It's not that the explanations of what's going on are poor, it's that there are very few occasions where the output generated by the example programs is shown, so you'll need to run the code snippets through the Perl interpreter to really see what's going on. Thankfully, the book's web site includes all of the source code used in the book as a downloadable, compressed tar archive.
Despite using Perl as my primary programming language for the last few years, and despite having read more Perl books than I care to mention, I was pleasantly surprised to find that Core Perl taught me a few new things about the language. We all know Reuven knows his Perl. In Core Perl, he proves it. I was also pleased to see Reuven describing release 5.6.x of Perl, which means that his description of the language is up-to-date.
In addition to some screenshots in the latter chapters, I'd suggest a few additions to a future edition of the book. It would be nice to have some extra appendices covering in sufficient detail the acquisition, installation and configuration of some of the book's core technologies, for example, PostgreSQL, Apache, mod_perl, and HTML::Mason. Also, in Chapter 17 ("mod_perl"), it would have been more useful to see a larger httpd.conf extract, as opposed to the collection of small snippets scattered throughout the chapter.
I have a few more gripes.
Although the writing style is informal (and very like the familiar "At The Forge" columns), I was struck by Reuven's use and heavy reliance on forward references. Naturally, a certain number of these are unavoidable, but there is an awful lot of them. This is especially noticeable in the earlier chapters. For readers already familiar with Perl, such a style is not a huge problem. However, for a reader from another programming background, it may become quite tiring to constantly jump forward in the text to read about a feature that is used earlier in the book but not discussed in detail until later. A particularly bad example of the problems this can result in is on page 107 when zombie processes are being discussed. The reader is referred to Section 4.7.4 for more details. Section 4.7.4 refers back to page 107, before referring the reader to the perlipc on-line documentation.
I was also surprised (and a little disappointed) by the number of errors I found in the text. Without wishing to be unkind, the first printing of Core Perl is riddled with errors. After reading the book, I had close to 70 queried errors to send to Reuven. Some are trivial typos (or typesetting errors), others are coding errors and yet others are problems with some of the explanations. To Reuven's credit, he has an errata on the book's web site, and he has included a description of the errors I found as well as a few others on the errata page. Also, Reuven tells me that any errors uncovered in the first printing will be fixed by Prentice-Hall in subsequent printings. If you do purchase a first printing, print out the errata and keep it close while working through Core Perl. Note that despite these problems, I do intend to recommend Core Perl to my students. The material is good, even though I have some problems with how it is presented.
Paul Barry lectures at The Institute of Technology, Carlow in Ireland. He is the author of Programming the Network with Perl, published by John Wiley & Sons Limited.
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
|Non-Linux FOSS: Seashore||May 10, 2013|
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- BASH script to log IPs on public web server
48 min 5 sec ago
4 hours 23 min ago
- Reply to comment | Linux Journal
4 hours 56 min ago
- All the articles you talked
7 hours 19 min ago
- All the articles you talked
7 hours 22 min ago
- All the articles you talked
7 hours 24 min ago
11 hours 49 min ago
- Keeping track of IP address
13 hours 40 min ago
- Roll your own dynamic dns
18 hours 53 min ago
- Please correct the URL for Salt Stack's web site
22 hours 4 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?