Perl: The Programmer's Companion
In the December 2000 issue of Linux Journal, I reviewed the latest edition of the classic Perl text: Programming Perl, 3rd Edition (or The Camel for short). In that review, my advice to new Perl programmers was The Camel should be "the second Perl book they should buy. The first should be Nigel Chapman's Perl: The Programmer's Companion.
Written originally in 1997 (with the third and most recent printing in June 1998), Chapman's book is now somewhat long-in-the-tooth as Perl books go. Despite this fact, it remains one of the most readable introductions to the language. In 280 pages (organized in 11 chapters), the reader is taken on a journey that transforms them from Perl newcomer to Perl programmer.
Up first is the obligatory "why this book was written" preface, which includes details on the syntax diagrams used throughout the text to describe Perl's programming constructs. Syntax diagrams are very much a tool of computer scientists, and Nigel Chapman is proud to be one. His is a programming book for programmers. If you are new to programming, look to another book to get you started.
The journey begins with a short introductory chapter on Perl as a programming language--why Perl is useful (and worth using), how it differs from other programming languages, its relationship to CGI, its general characteristics and, of course, a discussion of why it is perfectly okay to do the same thing more than one way in Perl.
Chapter 2, "Simple Text Processing", dives right in. On page 11, Chapman treats the reader to an excellent tutorial on Perl's regular expression technology, and the tutorial runs for the next fifteen pages. Regular expressions support the use of Perl as a text processing language, and a rich collection of idioms are presented and explained in sufficient detail to give the reader a thorough grounding in all things pattern-matching. At the end of the chapter, filehandles are introduced (together with some sound words on comments and code layout). Amazingly, by the end of the first chapter, you will already know enough Perl to do some useful things.
Chapter 3, "Scalar Values and Variables", builds on the material from the previous chapter and, using some simple examples, explains the ins-and-outs of using Perl's "one of something" variable container: the scalar. Perl's in-built operators are explained, in addition to Perl's rather unique notion of "truth". Assignment, strings and variable interpolation are covered, too, and a small number of in-built subroutines typically used when working with scalars are presented. The chapter ends with two small, but complete, Perl programs that demonstrate the idioms seen thus far.
The author uses the "Flow of Control" chapter to describe the usual compound statements: if, while, until and for. The creation of user-defined subroutines, in addition to the do and eval in-built subroutines is also covered. The real-world example in this chapter involves building a small compiler/translator that was actually employed in the production of the text. This example may be a little involved for some, but it does showcase Perl and consolidate the material covered in the first four chapters.
In addition to the "one of something" scalar, Perl provides great support for "collection of something" variable containers. Chapter 5, "Lists and Hashes", covers the creation and use of Perl's in-built lists, arrays and hashes. A collection of related in-built subroutines are also described, and the chapter is littered with good examples and code snippets. With arrays covered, the author returns to subroutines and explains how arrays are used to support subroutine arguments. The foreach statement is also described, as its use is almost exclusively associated with Perl arrays.
File I/O, formats and directory access are the subject of Chapter 6, "Input, Output and Files". Again, there's plenty of code here, and some small, complete examples support the discussion of these topics. The use of pack and unpack in-built subroutines are described in relation to the processing of binary data within Perl programs.
By the end of Chapter 6, readers of this book should already be competent Perl programmers. Certainly, enough material has been covered to do quite a bit of work in Perl. The next three chapters introduce what I would typically describe as advanced features of the language. Chapter 7, "References and Data Structures", does a good job of presenting one of the most confusing parts of Perl: reference syntax. A data structure example, half way through the chapter, presents the Perl implementation of an algorithm from Donald Knuth's "The Art of Computer Programming". The code is surprisingly short and easy to follow. The latter part of the chapter covers references to subroutines and their uses. Chapter 8, "Objects", presents the Perl object-oriented features. It is not a detailed treatment, but it's enough to give a flavor of how OO works in Perl. A small class is developed, together with appropriate documentation in Perl's POD markup technology. Chapter 9, "Using Modules", describes the other major code reuse mechanism in Perl: modules. There's a light treatment of how to create a custom module from scratch, and a brief review of the Perl pragmas of most interest to module writers. However, the bulk of the chapter is dedicated to surveying a batch of third-party add-on modules to Perl. Topics covered include: configuration, code timing, date manipulation, OO filehandles and persistent hashes. The chapter concludes with a short description of the standard Perl library and the CPAN.
Chapter 10, "Perl and the World-Wide Web", presents a tutorial on CGI programming for the uninitiated. Some simple CGI's are created before the author presents a more complicated HTML forms-processing example. A very brief discussion of other networking and Internet modules rounds out the chapter.
The final chapter provides pointers on where to look on-line for more information on Perl. A number of books are also recommended. In evaluating Perl, the author describes Perl as it relates to other programming languages that came before and influenced Perl: Snobol and Awk. Perl's historical relationship to UNIX is also presented, as is a comparison to TCL and Python. In the final section, entitled "Hats Off to Larry?", the author begins the section with what has become one of my favorite sentences describing Perl: "Sometimes, it may seem as if Perl deliberately trails its coat in front of the mainstream programming languages, trying to start a fight." The author concludes with a honest assessment of Perl, warts and all.
Perl: The Programmer's Companion is rounded off with an epilogue, a set of exercises and index. The Epilogue documents a (fictitious) conversation between three programming language experts: Ed, Harry and Bernie. It is left as a exercise to the reader to work out who the three experts actually are. The Exercices, available as part of the third printing, cover chapters 2 through 11. They are of sufficient depth and difficulty to keep even the most confident Perl programmer busy for quite some time. The author suggests, rather tongue-in-cheek, that readers "re-do all the above exercises in C++ or Java" as the sole exercise for Chapter 11.
So, is this the perfect introduction to Perl? To be honest, it is not far off. If I was to get picky, I'd have to say the authors use of the use English pragma throughout all of his code annoys me, but that's a personal preference. If Perl has taught me anything, it's that it is quite alright to do things in Perl in whatever way suits you. It would also be remiss of me not to mention that Perl (the programming language) has changed a little since Nigel Chapman wrote his book. Some of the newest features are (obviously) not covered in this text. It is one of my secret hopes that Mr. Chapman revise Perl: The Programmer's Companion when Perl 6 is released (hopefully, sometime next year).
I first read Perl: The Programmer's Companion in 1999. I credit this book as being the one that really turned me onto Perl and made me a Perl programmer. As part of my courses at The Institute of Technology, Carlow (Ireland), I now include a whistle-stop tour of Perl, and Chapmans's is the book I tell my students to buy (first). I've gone on to read more Perl books than I care to mention, but, despite this, I often find myself returning and referring to Perl: The Programmer's Companion.
But don't take my word for it. The authors of Programming Perl (O'Reilly 2000) and Perl Cookbook (O'Reilly 1998)--two of the most revered titles in the Perl universe--include Nigel Chapman's book in their list of recommended texts for newcomers. Tom Christiansen refers to the book as nothing short of "delightful". This is high praise indeed from Perl's inner circle.
Paul Barry (firstname.lastname@example.org) lectures in computer networking at The Institute of Technology, Carlow, in Ireland (www.itcarlow.ie). He is the author of Programming the Network with Perl, which will be published by John Wiley & Sons.
Practical Task Scheduling Deployment
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.View Now!
|The Firebird Project's Firebird Relational Database||Jul 29, 2016|
|Stunnel Security for Oracle||Jul 28, 2016|
|SUSE LLC's SUSE Manager||Jul 21, 2016|
|My +1 Sword of Productivity||Jul 20, 2016|
|Non-Linux FOSS: Caffeine!||Jul 19, 2016|
|Murat Yener and Onur Dundar's Expert Android Studio (Wrox)||Jul 18, 2016|
- The Firebird Project's Firebird Relational Database
- Stunnel Security for Oracle
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide