Updates to Chapter 15, “Smart matching and given-when”

[This post notes differences between the fifth and sixth editions.]

The chapter on smart matching and given-when is the newest chapter, but also the one a bit out of date. Since we were writing the fifth edition right on the cusp of the release of Perl 5.10.0, we weren’t aware of all the problems that the new smart match feature had.

I did start to find problems, and I posted to perl6.language, perl5.porters and perlbug around the time we were turning in the book which hit the shelves in June 2008. It takes about four months to go from the end of writing to delivering the dead trees to the reader.

No one had an answer, and the next version of Perl changed quite a bit of the smart matching mechanism. For instance, see my p5p messages for [PATCH] perlsyn: equivalent code for HASH ~~ ARRAY and [perl #50538] when( @n && %n ) fails to smart match.

Updates to Chapter 5, “Input/Output”

[This post notes differences between the fifth and sixth editions.]

With the added emphasis on Unicode, we had to update the chapter on input and output a bit. If we are going to talk about Unicode, we need to talk about encodings, which expands the material on three argument open and brings in binmode too.

For this update, we also introduced filehandle references, although we did not call them references, really. We still present most of the chapter using bareword filehandles, and once we have covered everything we show how you can do the same things with filehandles in variables. However, we still save the meat of filehandle referencs to Intermediate Perl.

Some people think everyone should be using lexical filehandles all of the time, but even if you want to do that for new code, you still have to understand what people did in old code so we have to cover the legacy syntax (and some people would even object to calling it “legacy”).

Learning Perl Turn-in day

I have to turn in Learning Perl, 6th Edition today so it can enter “production”. This is when the O’Reilly staff essentially take the book away from me, turn off my repo access so I don’t keep fiddling, and make the book look great.

As part of that, the editor reads over the book , although there aren’t any surprises because we’ve talked about everything I was doing along the way. The graphic designers turn my crude conceptions of the figures and turn them into nice looking figures, an indexer creates the index, and many other things. This is when O’Reilly knows they have a book to sell and can start planning for its print run and delivery to bookstores.

On my side, this is where I take a break from thinking about the book for several weeks so I can forget about how hard it is to pull something like this together. The next time I think about the book is when O’Reilly sends me the “QC1 proof”, which should be close to the final form save some minor corrections and typesetting adjustments.

A new Unicode appendix

I’ve added a new appendix to Learning Perl to handle all of the Unicode stuff I was having difficultly integrating into the other chapters.

Our goal has always been to present just the information you need without getting into distracting details. The problem with Unicode is that there are a lot of distracting details. Not only that, you have to learn some things in tandem. We can’t talk about Unicode strings without introducing strings, but at the same time, we want to start with Unicode as the basis for strings.

I wanted to have a lot of that stuff in the Strings chapter, but a lot of the Perl Unicode stuff lives in modules. We do talk about modules later in the book, but I want to use some of them earlier.

Any beginning book is going to have this problem. You need to ignore some stuff to at least get started. As such, I gave up on trying to cram all the Unicode stuff into the chapters and put most of it into a new appendix. This also means that if people want to ignore some of the Unicode stuff, which I don’t recommend, they can. But, they shouldn’t. So, read the whole book, even the appendices!

Updates to Chapter 9, “Processing Text with Regular Expressions”

[This post notes differences between the fifth and sixth editions.]

I didn’t have to make many changes to this chapter. I wanted to put in at least one Perl 5.14 feature, but the only new thing that the substitution operator gets is the /r modifier.

While working through this chapter though, I started to wonder if our terms in the previous editions were the same in the Perl documentation. We called the modifiers “option modifiers”, and sometimes “flags”, perlre just says “modifier”. Personally, I’m used to saying “flag” all the time and I like that term just fine, but for regular people, there’s nothing to connect the everyday use of “flag” to the thing after the match operators. So, “modifier” it is. I’d much rather use “adverb”, which is popular in Perl 6 land, but it’s a bit late for Perl 5 to change terms. When I made the switch in this chapter, I had to go back to Chapters 7 and 8 and do the same thing.

This chapter is also curious in that it ends with a long example the builds up to a perl one-liner. One of the things the reviewers noted about a new edition was a new chapter devoted to one-liners. That’s still possible, I guess.