What’s new in perl?

For about four years, I’d been living in perl 5.8.8. land at the BBC, and some unicode issues aside, not really been fussed about recent perls. I’d had a nagging feeling that I’d been missing out on shiny new features that would make my life so much easier. Also being constantly being berated on the #london.pm IRC channel about being a laggard didn’t help. So, having had the links to the release notes thrown at me, here is an incomplete list of what’s new.

As an aside, and on the back of work I did for Photobox and some BBC projects, here is a piece of advice: do NOT use the system perl. That way lies much pain. Treat your perl as part of the *application* stack. There is no reason not to. These days, with perlbrew and cpanm, and a well-maintained Makefile.PL you have total control of the software that runs your software. Pity those poor folks with other languages.

So here is a list of the new stuff:

  • “say” appends a newline to a print.
  • Persistent private variables:

 

use feature 'state' ;
sub thingy { state $x ; return ++$x }
  • Smart matching:
$a ~~ /foo/;
$a ~~ @list;
  • Switch:
use feature switch;
given ($foo) {
    when (/abc/) { $abc =1; }
    when (/def/) { $def = 1; }
    default { $default = 1}
}
  • Defined-or operator:
$a // $b ;
defined $a ? $a : $b ;
$c //= $d;
$c = $d unless defined $c ;
  • A fun operator. I’ll let you work this one out.
...

Aside from these, most of the work has been going on under the hood: a huge number of bug fixes, performance enhancements and a massive chunk of work getting Unicode “right”. I wouldn’t have dreamed that there are over 250 Unicode characters that match \d for example. But it doesn’t matter, now it’ll JFW.

So, on the surface, it doesn’t seem much has changed but even if you can’t see it, it has and I would encourage anyone using an old perl to at least start developing on a new perl, move to building and shipping your own perl (maybe even built with gentoo-safe flags for your hardware for extra jiggyness) and joining the new decade!

[Bloglines] [del.icio.us] [Digg] [Facebook] [Google] [Reddit] [Windows Live] [Yahoo!] [Email]

Related Posts:

2 Responses to “What’s new in perl?”

  1. Alan Rocker says:

    Although I haven’t been following the controversy too closely, I understand that smart matching isn’t. Not every new feature turns out to be a good idea, (unlike “say”, which saves all kinds of trouble).

  2. Dave Cross says:

    Yeah, the definition of smart match has changed with every version of Perl released in the last five years. I’m very careful about how I use it.

    And, Dave, everything you’ve mentioned was new in Perl 5.10 over five years ago. Plenty of other stuff since then. See http://www.slideshare.net/davorg/modern-core-perl (which is, in itself, now eighteen months out of date).

Leave a Reply