Skip to content

What is Modern Perl?

2012 June 25

After a gap of twelve years, a new edition of Programming Perl (affectionately known as “the Camel book” to its many fans) was published earlier this year. That came as quite a surprise to many people who had given up on seeing a new edition.  What has changed in the new edition? Does the book now cover Modern Perl? The answer depends on what you mean by the term “Modern Perl”.

The term Modern Perl can mean a couple of things to different people. Sometimes it means those two different different things to the same people. It depends on context. That’s a joke for the Perl programmers.

The first, and probably the most common meaning of the term is as a catch-all description for the big CPAN projects that have transformed Perl programming over the last five or ten years. Where Perl programmers once painstakingly constructed classes and objects using blessed references, we now use Moose. Where we once talked to databases using DBI, we now use DBIx::Class. Where we once reinvented wheels every time we wrote a CGI program we now use powerful web frameworks like Catalyst, Dancer or Mojolicious – all of which use PSGI to make it simple to deploy our application in various environments.

That’s not to say that the older approaches no longer work. Perl has a long tradition of backwards compatibility and many of these newer tools build on the older ones. A Perl class built with Moose will be exactly the same blessed reference as a manually constructed one and DBIx::Class still has plain old DBI lurking at its core. So using the old tools still works fine, but using the newer tools (the Modern Perl tools) will make a programmer more productive and a program easier to maintain.

So that’s what many people mean by Modern Perl a lot of the time. And is that covered in the new version of the camel book? Well, no. The camel book has traditionally covered the core of Perl and has largely ignored both CPAN and the practical uses of Perl. Which means that these Modern Perl tools largely fall outside of the book’s scope. The camel book doesn’t cover either database connections or web programming, so DBIx::Class and PSGI never get a mention. Object oriented programming is covered in chapter twelve of the book, but that’s almost all about the traditional way of writing classes in Perl. Moose gets a brief mention at the end of the chapter as an alternative approach which is well worth investigating.

If the camel book doesn’t cover these big Modern Perl projects, then was it really worth publishing the new edition? Is it worth buying a copy? Well, yes, because there’s the other kind of Modern Perl which is covered in some depth.

The third edition of the camel book was published when Perl 5.6.0 was the current version. We’re now on Perl 5.16.0. Between the two there have been about twenty stable releases of Perl. Over those twelve years a lot has changed in the core of Perl. It’s been slow and incremental and people who haven’t been keeping up with the perldelta manual page  might not have noticed, but there have been a huge number of improvements. Little changes that make your Perl programming live easier, your Perl programs easier to write and easier to maintain. Here are a few examples.

  • The state keyword allows you to to have variables that are scoped to live within a subroutine but which maintain their values between calls to the subroutine
  • Perl now has a real switch statement
  • File handles can be stored in scalar variables – and can therefore be automatically closed when a lexical variable goes out of scope
  • Perl’s support for Unicode is equal to, if not better than, that in any other programming languages
  • Regular expressions have gained many new features

This list just scratches the surface. Core Perl has gained many more new features in the last twelve years. There are also the many new modules that been added to the core distribution – very useful things like Test::More, List::Util, Time::Piece and autodie.

The Perl of 2012 is substantially different to the Perl of 2000. But many people don’t seem to realise that. Because the definitive Perl reference book hasn’t been updated, it’s easy to believe that Perl itself hasn’t been updated. On various mailing lists and web sites I constantly come across people who write Perl like it’s still 2000 (or, in many cases, even earlier). Their code still works, of course, but because they haven’t been keeping up with the way that Perl has evolved they aren’t using many tools and techniques which would make their lives easier.

That’s what I see as the most important reason for the new edition of Programming Perl. The definitive Perl book is now up to date with the way that the best Perl programmers now program Perl. No, it doesn’t cover DBIx::Class or PSGI, but that’s not important. It covers hundreds of small ways that Perl has changed and improved over the last twelve years. Programmers buying this edition will have their eyes opened to a whole new world of Perl programming. Their Perl programming lives will become easier. They will be using Modern Perl.

If you’re interested in hearing more about Modern Perl (in both of its meanings) Dave Cross (@davorg) is running a low-cost one-day course in London on 6th October. See Perl School for more details.

13 Responses Post a comment
  1. avatar
    September 6, 2013

    Excellent review of the new “Camel Book”. I have the old Third Edition from 2000. You bring up excellent reasons for upgrading the classic Perl reference, which has been my go-to Perl book for a decade. But you are also right in mentioning that many things have changed about the Perl languages. There are so many new things I need to learn about Perl, so I am going jump into the deep-end and go with something more bleeding edge. The reviews I’ve read about the Modern Perl book makes that look like a better choice for my situation. I am mostly a real-time C++ programmer, but every once in a while I just need to write a Perl script. The really great news is that the Modern Perl book can be downloaded in PDF format directly from the publisher for free! How cool is that? And it reads like a modern text book rather than a reference book, so that’s a much better format for learning about changes to a language.

    So my immediate needs for updating my Perl skills have been instantly satisfied. I have a brand spanking new Modern Perl book to read for free, and I now know that my old Perl reference book is out-of-date. I will be looking to upgrade it, when I can find a good price for the 2012 version. Thanks.

  2. avatar
    Blessed Geek permalink
    July 8, 2012

    Wouldn’t it be a spontaneous response for a group of Perlites (apologies for the pejorative term) to come together to create an “open source” project to write a double-humped camel book to cover all those things the single-humped book would not cover?

  3. avatar
    Russum permalink
    June 27, 2012

    So what’s a good book that covers all that “modern” stuff like DBIx::Class and PSGI?

  4. avatar
    June 26, 2012

    Interesting summary of changes to core Perl in the last decade. To what extent have new features like the ‘state’ keyword found their way into the most used CPAN modules?

    • avatar
      Dave Cross permalink
      June 26, 2012

      That’s an interesting question. Obviously when you’re writing CPAN modules you’d like them to be useful for as many people as possible. Which means that you can’t use features from the latest version of Perl if you know your users are using, for example, Perl 5.8.8.

      Whenever CPAN authors meet up, this will be one of the topics of conversation. Some people follow the standard Perl support policy (only supporting the two most recent major versions of Perl). Others go to the opposite extreme and deliberately eschew all modern Perl features in order to support ancient versions of Perl.

      I’m somewhere inbetween. Currently my modules all support Perl 5.6.0. But I’m seriously considering changing that. I’m not sure where I’ll draw the new line. Perl 5.8.8 seems to be the earliest version that still has a reasonably large installed base. But 5.10 has a lot of useful new features.

  5. avatar
    Christian Walde permalink
    June 26, 2012

    > The definitive Perl book is now up to date with the way that the best Perl programmers now program Perl.

    Yet when i bought it, one of the first things i encountered were bareword file handles.

    Mind, this doesn’t mean it’s the only issue. It takes an ungodly long time to introduce strict/warnings and when it gets around to them only does so in a very offhand way while introducing other topics. It needlessly quotes the keys used to access hashes and it even uses old sub calling conventions ( &fetch() ).

    It may try to target modern Perl usage even without touching on CPAN, which is perfectly possible, but covering some new features doesn’t cut it if your base material isn’t up to scratch.

  6. avatar
    Michael Caron permalink
    June 25, 2012

    Yeah… Perl has a switch statement, but you still shouldn’t use it as there’s some dangerous things that could still happen.

  7. avatar
    David Mertens permalink
    June 25, 2012

    I think that the Camel book’s focus on the core is spot-on: it should not go into detail about why Perl is used in its current niches because those niches will undoubtedly change as time passes. It is important that The Reference for the Perl language indicate how to program in the language, not in the niches.

    Currently, many programmers are employed for system and web administration. This is why Perl’s ecosystem has so much for handling web stuff. However, programming jobs are opening up in the smartphone industry and there are plans to port Perl to Android soon. Once the port is in stabilized and development picks up for smartphone programming, I expect Perl’s CPAN to start filling up with modules related to those tasks. CPAN will have lots of churn, but the core language will slowly progress, picking out the best ideas vetted on CPAN. And even when smartphones become a big employer, the Camel book will still be an excellent language reference for smartphone developers, as well as system administrators, web programmers, and everyone else who find a use for Perl.

Trackbacks & Pingbacks

  1. Week Notes 26 & 27 | Davblog
  2. Quora
  3. Re: What is Modern Perl? | Programming Perl

Leave a Reply