Skip to content
Categories:

How to try the newest perl version easily

Post date:
Author:

It’s been already 10 years since I programmed much Perl, but I still have a soft spot for the language. Nowadays I write mostly Python and JavaScript and hardly ever write perl, but I still maintain a couple of Perl modules on CPAN and also I’m still a subscriber of the Perl Weekly newsletter.

In this weeks’ edition, editor Mohammed Anwar discussed the upcoming perl 5.40 release and mentioned that he could not wait to try it. Well, the good news is, you don’t need to, and also, probably you shouldn’t.

The perl release cycle

Perl has yearly releases, which typically are released end of May (the 5th month, for Perl 5, you see?) so we’re very close to the planned release for perl 5.40.0 at this point. This is than the newest stable version, replacing 5.38.x from last year. But, typically every month, a development release is created, with new features. These development releases have an uneven minor version number. So when 5.38.0 was released, 5.39 was also released, where the new features go. And every month there will be more features, and bugfixes, and then it’s stabilized, and then it’s end of May and you get a new perl. Right now, we’re on perl 5.39.10. You can check the new features in ‘perldelta.pod

Why you might want to check out the development releases

Some people do not care about new versions of perl and they just run with whatever comes with their enterprise linux distribution, and that’s fine. But some people, like Mohammed, get really excited about new features and want to try it. And some people for instance have some published modules or some code that they might want to test with the new perl. Or they just want to write small one-off scripts using new language features, for fun and giggles or for other work. And testing is also great, because in the development cycle — especially early on in the development cycle — it is still rather easy to make changes to a design or fix issues, so it’s also a great opportunity for testing or feedback.

How to install a different version of perl on your system

For installing multiple different versions of perl, I use plenv. It allows you to install multiple different versions at the same time. You can choose a different perl version for your running shell, or for a certain directory, or globally. So for instance, you could run everything in ~/work/ on 5.36 while ~/private/ is on 5.38 and ~/private/newstuff/ is on 5.39.10! (There is also rbenv for ruby, and pyenv for python, which work very much the same. The latter I use a lot!)

If you set up plenv, you can get a list of installable perls using plenv install --list and then you can install the latest development version using the -Dusedevel flag:

plenv install 5.39.10 -Dusedevel

Then you can switch to this perl in your shell using

$ plenv shell 5.39.10

$ perl --version

This is perl 5, version 39, subversion 10 (v5.39.10) built for x86_64-linux

$ perl -M 'feature(":5.40")' -E 'try { 1/0; } catch ($e) {warn "Hey there: $e"}'
Hey there: Illegal division by zero at -e line 1.

There, you can see we use perl 5.39.10 in your shell — this makes sure you’re back to ‘normal’ the next time around. And I show off two new features: I use a ‘feature bundle’ that causes ‘try..catch’ to not be marked as experimental, and the -M command line flag to perl now allows a space before specifying the module name.

Happy perling!