Updates to Chapter 4, “Subroutines”

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

There’s not much to write about Perl subroutines that we haven’t written before, but that doesn’t mean that this chapter gets a pass in the update. This is only chapter 4, so it’s still early in the book. Up to this point, we have only covered the basics of Perl scalars and arrays. Once we get into subroutines, we start to talk about scoping variables to a block, and it’s here that we introduce lexical variables.

Once we show of my, we can tell people about strict. Still, that’s nothing new. However, since the last time we wrote about strict, it was something that you had to enable on your own. Perl 5.12 added the feature that you’d get that for free by requiring the version of Perl.

Before Perl 5.12:

use 5.010;
use strict;

Starting with Perl 5.12:

use 5.012; # strict for free

We could tell them how to turn it off, but we still won’t do that until Intermediate Perl.

Updates to Chapter 6, “Hashes”

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

I didn’t have much to update in the hashes chapter, so when you get to Perl 5.14, you’ll find that Perl’s hash features are the same things you had in previous versions of Perl.

However, I did move the “fat arrow”, => stuff from Chapter 17, “Advanced Perl Features”, to the hash chapter. Why have it so far away? It’s just a couple of paragraphs, so it’s moved up to the first half of the book.

Updates to Chapter 13, “Directory Operations”

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

Our updates to Chapter 13 aren’t that exciting. There’s not much that has changed in the world of Perl and directories. It’s almost dull, even.

  • Use variables as directory handles: opendir my $dir, $directory.
  • Mention a couple more modules incidental to some of the examples, including File::Spec::Functions, Path::Class, and File::Temp
  • Show a find2perl example. We mentioned File::Find only to say that we weren’t going to say anything about it. Also mention the improved interfaces of File::Finder and File::Find::Rule

Updates to Chapter 7, “In the World of Regular Expressions”

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

I just committed the new Chapter 7, “In the World of Regular Expressions”. It was quite an education, even for me, because the character class stuff has changed so much since Perl 5.6, and, since Learning Perl had been ignoring Unicode, we didn’t face the hard problems.

  • The \w character class is almost dangerous now. By default, it represents over 100,000 characters that can match at that position. The \d and \s character classes have the same problem on a smaller scale. It’s unlikely that anyone actually wants these shortcuts anymore, but there are still in older programs. I did cover this over at The Effective Perler, too.
  • Since we’re covering Unicode, this is the right chapter to cover the Unicode properties, such as \p{Space}. Those don’t completely solve the character class shortcut problem because they still match many characters. The perluniprops documentation lists how many characters match each property, which is kinda cool.
  • Perl 5.13.9 includes Karl Williamson’s work to add the /a adverb to enforce ASCII semantics, so we use that
    too even though we don’t really get into options into the next chapter.

This is all rather painful to update because I didn’t want to go through everything assuming ASCII semantics (so, very few changes) then tack on an “if you are using Unicode” section that then invalidates everything. We just have to bite the bullet and make the switch to thinking of Unicode as the default and ASCII as the backward-compatibility special case.