Modern Perl, 4th Ed

Author: Chromatic
Publisher: Pragmatic Bookshelf
Pages: 286
ISBN: 978-1680500882
Print: 1680500880
Audience: Instructors,students, programmers in a language other than Perl
Rating: 4
Reviewer:Nikos Vaggalis 

The book that sets out to explains Perl from its philosophical roots to its everyday pragmatic practice has been updated to cover Perl 5.22 .

Here on i-programmer we've already pointed out that documentation can become the Achilles heel of an open source project, having a greater influence on the project's life span than the conveniences that it offers. 

This becomes even more important when the project is as huge as Perl. Fortunately, Perl is deluged with quality documentation and books, one of the reasons that it has made it thus far; well, add one more to the count...

The need for quality documentation and ways of getting hold of it are acknowledged as before tackling anything else we meet perldoc . 

Then it sets out the philosophy Perl was built upon, mainly expressiveness and productivity, nicely described with:

 "You don’t have to understand every detail of Perl to be productive"

as well as its laxness described in:

"Other languages may claim that there should be only one best way to solve any problem. Perl allows you to decide what’s most readable, most useful, most appealing, or most fun" 

Continuing, the double-edged sword of Contexts is outlined, this is a powerful notion, but one that is dangerous to the uninitiated. Then
void, list, scalar, numeric, boolean, string, contexts are  
illustrated with examples that demonstrate how they alter code's behavior.



Chapter 2 is about another powerful aspect of the language, not built in but an extension to it, that is, the vast pool of self contained components called modules which you can leverage in your code to take care of pretty much anything from the simplest tasks to the very complex ones. Therefore you have to know how to install a CPAN client and be able to download and install the needed modules. 

The process described is pared down to the bare essentials, I guess deliberately done to keep it simple

After that,Chromatic recommends a few on-line resources and forums where you can get help when needed, but the No1 Perl Community site, Perl Monks, is noticeably absent and no reason is given.

Chapter 3 is where we start exploring the language itself. I must say that I enjoy the author's aphorisms, such as: 

"You can write effective Perl code without knowing every
detail of every language feature, but you must understand how they work together to write Perl code well language itself."

It goes to show that the pages of this book are diffused with Perl's philosophy, considered an integral part of it. 

So we get to the raw building blocks,starting from zero. When talking about Names(Identifiers), Variables, Namespaces, etc It does so by not only explaining how Perl in particular goes about them but also by exploring their essence.  For example:

"A variable in Perl is a storage location for a value"


"Variables allow you to manipulate data in the abstract. The values held in variables make programs concrete and useful. These values can be your aunt’s name and address, the distance between your office and a golf course on the moon, or the sum of the masses of all of the cookies you’ve eaten in the past year"

Descriptions like this clearly indicate that this is a book not only about the Perl language, but also the concept of programming catering for beginners who are encountering their first programming language. Providing a synopsis of these fundamental programming principles, also renders it as an educational springboard. 

There are cases however when new terminology is used up front , not being explained in place but delayed until much later on. For example, as early as the first page of Chapter 3, the term function is used, and is used repeatedly in the chapter, although not fully explained and analysed until Chapter 5.

Presuming that this is a book that targets beginners, this complicates rather than simplifies things. Another example of the same, is on the use of the use strict pragma, mentioned in the same chapter but analysed in Chapter 12,thus forcing readers to do a context switch to page 172 before returning to  continue where they left off.

The chapter reaches an end by going over the rest of Perl's essential building blocks: arrays, hashes, packages, references and nested data structures.

Chapter 4 Operators can be made to seem very theoretical. Ideas like  Precedence, Associativity, Arity ,Fixity,  are made concrete by examples in code. Again, the advantage of explaining a principle in such a brief but clean way, works well. It concludes by looking at Perl's actual operators such as Logical, String, Numeric, etc.




Chapter 7 undertakes the daunting task of trying to walk the beginner through the principles of OOP. It does so by teaching Moose, Perl's post-modern OO system, setting the bar on what's required by Modern Perl. This is a good strategy as old-school object orientation might be flexible but at the same time too lax and clunky. If you've been used to the classical OO paradigm adopted by most other languages, like Java or C#, then it would feel very awkward adapting to Perl's. So Moose is an object system but of course being Perlish it couldn't come without some non-standard twists; Roles and their Composition being an example. 

Moose provides private attributes, accessors and type validation out of the box, helping the programmer to write more clean and organized code.

I also find refreshing to see that Polymorphism is introduced before Inheritance, since in Perl two classes may be not parent-child related for polymorphism to take place. So this way things are cleared up early on, since the other way around, the way it happens in most other languages, would give the false impression that a parent-child relationship is absolutely necessary. Perl's approach is called Duck Typing

After Moose, the book tackles old-school Perl. As to why, when this is a book about Modern Perl , I can only guess that that's because most modules are written that way and hacking on them would require that kind of knowledge. It also provides a much more complete appreciation of Perl's OO approach.

To sum up this chapter in a single word, I would say "precision", as looking up entries like Inheritance, Polymorphism or Roles in an idealized dictionary would lead to the same brief but precise and clean explanations. On the other hand beginners could be easily overwhelmed by not being able to digest all that information presented in that manner. 

And that's the reason why I think that this book is suitable as a guide to instructors teaching the basics to a Computer Science class of first year students, playing the role of the middleman trying to convey its rich and vast information to them. For the self-taught beginner however, I would still recommend the other Perl classic, Learning Perl, aka the Llama book.

Chapter 8 contains valuable tips on how to become a better programmer mainly by writing Maintainable, Effective and Idiomatic code:

"a beautiful program that never delivers value is worthless, but an awful program that cannot be maintained is a risk waiting to happen".

Of course an integral part of this process is testing and communicating warnings and errors to the user, covered in detail in the Chapter 9 on Managing Real Programs. This chapter is a treasure trove of concentrated best practices such as: 

"If you enable fatal warnings, do so only in code that you control and never in library code you expect other people to use"


"older code often uses the two-argument form of open(), which jams the file mode with the name of the file to open:
Perl must extract the file mode from the filename. That’s a risk; ....The three-argument open() is a safer replacement for this code"

It's a good read for people still living according to Perl's old-school ways, which  allowed them to get their job done without being hustled by rules and warnings. Although Perl is flexible enough to allow the descent down that path to the "dark side",it does not necessarily imply that that's the right path to follow. (Sys admins are you listening?)

At the same chapter we find another hint in;

"Why Use while and Not for ? for imposes list context on its operands. When in list context, readline will read the entire file before processing any of it. while performs iteration and reads a line at a time. When memory use is a concern, use while."

Hints like this belong to the seasoned programmer level and
beginners are very fortunate to have met such advise that early on. Not only does it help them optimize their code, but also to learn the language and its idioms from the inside out. Organization wise the topics here are self-contained and don't have to be read in sequence Maybe the chapter's title would be better as 'Miscellaneous'

The best practices and the unravelling of Perl's secrets extend to Chapter 11: What to avoid, which sets out to show that besides Perl supplying flexibility, it also supplies enough rope to shoot yourself in the foot. 

For example:

 "Hash keys in Perl are usually not ambiguous because the parser can identify them as string keys; pinball in $games{pinball} is obviously a string.Occasionally this interpretation isn’t what you want, especially when you intend to evaluate a built-in or a function to produce the hash key"

The chapter's highlight is the Method-Function Equivalence subtopic which explains that Perl does not distinguish between a plain function and a method, and 'Automatic Dereferencing' which might be a convenience to the programmer, but can 'bite' as well. That and other numerous gotchas are exposed.

Chapter 10: Perl Beyond Syntax is a showcase of Perl's cleverness through its idiomatic behaviour, demonstrated by advanced techniques like the Swartizan transform. These techniques all serve as an appetizer to the level of power the student can achieve when the time comes

This is a book about the core of Perl. Some modules are mentioned along the way, but the focus is on the core. There's no Database interaction, Unicode, network programming and web frameworks utilization, as you can't have those without comprehending the core. Thus, Chapter 12, the final one, provides links and refers to well known MVMs (Most Valuable Modules, just coined the term) for going over common tasks such as Processing structured  data files through  Text::CSV_XS, and Accessing databases via SQL, through the DBI module.

It's also in this chapter where the use strict and the warnings pragmas are thoroughly explained, although they have been used throughout the book's code. It seems a strange decision to delay their appearance as most, if not all books tackle them at the beginning and not the end. But then, uniqueness is this book's characteristic.   

Summing up, it's not a good book, it's a great book.

Even if you are familiar with the language you will find stuff in it to keep you busy. Programmers in another language but new to Perl will also find value in the same way  the novice will. Just instead of wondering what an Iterator is, for example, like the novice would do, their focus will be on how an Iterator looks in Perl.  

In addition there is much educational value to draw upon as the book goes over programming principles, exemplifying them through Perl like a precise, no-fluff, fatless encyclopedia. It's this property that renders it as the ideal text book on Programming 101.

And most of all, what do you pay for it?

If you choose the e-book, zero. And if you buy the print version direct from Pragmatic Bookshelf the e-book is included free.That lifts the notion of value for money to another level. The truth is, it's a steal; I would definitely pay the price for this kind of work.

See our reviews of other Perl books


To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.



PHP In Easy Steps, 4th Ed

Author: Mike McGrath
Publisher: In Easy Steps
Date: April 2021
Pages: 192
ISBN: 978-1840789232
Print: 1840789239
Kindle: B08ZSV3MNH
Audience: People wanting to learn PHP
Rating: 4
Reviewer: Ian Elliot
PHP isn't a fashionable language, but this doesn't mean it isn't worth learning.

Domain Storytelling (Pearson)

Author: Stefan Hofer
Publisher: Pearson
Pages: 288
Audience: software architects
Rating: 4.5
Reviewer: Kay Ewbank

This book sets out to be a practical guide to database domains, bringing together domain experts, software developers, designers and bus [ ... ]

More Reviews

Last Updated ( Thursday, 12 November 2015 )