[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.
3 thoughts on “Updates to Chapter 4, “Subroutines””
Does this chapter mention that subroutines can be assigned to scalar variables and passed around as arguments, just like other values? Back when this book was first written that was an advanced concept, but functional languages are more prevalent today and it might be good to show that Perl is just as functional as the rest of them. I think a simple example that doesn’t get into the details of references, closures, or currying would suffice at this point. Perhaps an example of passing a callback function to another function, or a Visitor pattern example. Those techniques are simple but can still useful, even for sysadmin-style scripting.
Learning Perl is the bare basics for beginners. Once they get the hang of the stuff in Learning Perl, people can move on to Intermediate Perl where we talk about references, including subroutine references. To get even fancier with closures, there’s a lot in Mastering Perl. Anyone who wants to go the functional route, however, should dive into Higher-Order Perl.
BTW, thank you (and the other authors and everyone else involved) for putting out an updated edition. I’m really happy to see the renewed attention Perl is getting to let those outside the community know that we’re not just surviving, but thriving.
Comments are closed.