Hello, unfrozen Paleolithic Perl programmers! Welcome to 2016!
First, let’s start with the good news: yes, we’re still programming in Perl5 in 2016 (and yes, we think that’s good news). Indeed, most of the code you wrote in the past, before that unfortunate “Big Giant Hole in Ice” incident, will likely still work just fine on the current release of Perl5 — even if you originally wrote it against Perl 4 or even Perl 3.
Here’s the bad news: there’s been an incredible amount of innovation in not only Perl5-the-language, but also in Perl5-the-community and what the community considers to be accepted best practices and the right way to do things. It can be very frightening and confusing!
But wait, there’s more good news: if you come to this talk, you’ll get a guided tour of my (reasonably opinionated) views on what the consensus best practices are around issues such as which version of Perl5 to use, system Perl versus non-system Perl, Perl5 installation management packages, new language features and libraries to use, old language features and libraries to avoid, modern tooling, and even more!
Delivered at OpenWest 2016, 14 July 2016
3. Hi Hi I'm John
• VP Tech, Infinity Interactive
• Ex-biologist
• Linux
• Perl tribe
• Polyglot coder
• Just this guy, you know?
meet me!
4. I'M JUST A CAVEMAN
YOUR MODERN PERL FRIGHTENS AND
CONFUSES ME
I was inspired to write this talk by a few online friends who happen to be Perl programmers -- but they're not engaged with the community, they're just using Perl to get a job done, and there's a widening gulf
between what I think is reasonable and what they're doing -- so I wanted to put together sort of an info dump to bring people up to speed. this talk is going to a wide-ranging survey of what's happened in
Perl in the last 5-10 years.
14. 5.6.0 - 22 Mar 2000
5.8.0 - 18 Jul 2002
5.10.0 - 18 Dec 2007
5.12.0 - 12 April 2010
here's the release dates for several perl versions, starting with 5.6 (latest and greatest in 2001, remember)
15. 5.6.0 - 22 Mar 2000
5.8.0 - 18 Jul 2002
5.10.0 - 18 Dec 2007
5.12.0 - 12 April 2010
see that five year gap there? yeah, those were not great times.
16. 5.6.0 - 22 Mar 2000
5.8.0 - 18 Jul 2002
5.10.0 - 18 Dec 2007
5.12.0 - 12 April 2010
but, starting with 5.10, which sort of brought perl 5 back to life, and then particularly, since 5.12, we've had this great thing! ...
18. 5.12.0 - 12 April 2010
5.14.0 - 14 May 2011
5.16.0 - 20 May 2012
5.18.0 - 18 May 2013
5.20.0 - 27 May 2014
5.22.0 - 01 Jun 2015
5.24.0 - 09 May 2016
here are all the releases since 5.12. notice anything?
19. 5.12.0 - 12 April 2010
5.14.0 - 14 May 2011
5.16.0 - 20 May 2012
5.18.0 - 18 May 2013
5.20.0 - 27 May 2014
5.22.0 - 01 Jun 2015
5.24.0 - 09 May 2016
see those nice regular predictable releases, happening every year like clockwork? that's pretty cool.
underlying this is a regular series of dev releases (those are in odd numbered versions, e.g. 5.23 is the series of dev releases between 5.22 and 5.24), which happen on a
monthly cycle
20. Perl5
pumpking
credit for starting and more importantly continuing this goes to a couple of p5 pumpkings, which is what we call the person who is in charge of the Perl5 effort -- our
Benevolent Dictator for the Moment, if you will
21. 5.12.0 - 12 April 2010
5.14.0 - 14 May 2011
5.16.0 - 20 May 2012
5.18.0 - 18 May 2013
5.20.0 - 27 May 2014
5.22.0 - 01 Jun 2015
5.24.0 - 09 May 2016
Jesse
Rik
there were two pumpkings involved in this, Jesse Vincent for 5.12 and 5.14, and then Rik Signes for 5.16 thru 5.24 (which just came out a few months ago)
22. Regular
release
cycle
getting back onto a regular predictable release cycle has arguably been the single greatest factor keeping Perl5 relevant and catalyzing the Perl "Renaissance" you may
be hearing about
23. ❤ Jesse
❤ Rik
much respect to Jesse and Rik for the work involved in this, it was *not* a trivial undertaking to start or to keep going.
24. ❤ Sawyer
this is also a good time to mention that Rik retired from the pumpking role after releasing 5.24.0, and our new pumpking is Sawyer. Sawyer is great and as you can see
from this picture, he *really* loves hugs, so be sure to give him one when you see him at a conference.
25. Modern
Perl
modernperlbooks.com
Another catalyst for the Perl Renaissance is the book "Modern Perl", written by chromatic. He has made this freely available online; you can also purchase a paper copy
if that's how you roll.
26. ❤
chromatic
modernperlbooks.com
Writing this book was a tremendous effort and it's an absolutely essential read if you want to understand what we call "Modern Perl", or how we do Perl in the 21st
century.
27. Many
language
improvements
One of the main benefits of the regular release cycle has been a number of language improvements. I'm only going to talk about a few today, but you can always read the
'perldeltas', or change summaries that come out with each new release.
28. Unicode
support!
In 2001, the world of Perl 5.6, Unicode existed but wasn't very well understood or very widely used. Today, of course, we live in a Unicode world, and it's something all
programmers and languages have to deal with. It's kinda too complicated to get into here, so I'm just going to say that now we can get _really_ expressive in our Perl
code
31. This should be a familiar way of communication for you!
(okay, this is my last caveman joke...)
Perl unicode support got _ok_ in 5.12, and got good in 5.14.
32. false values: 0, '', ( ), undef
everything else is true
undefined values: undef
everything else is defined
Quick Perl background
Before I can explain this next one, I need to do a brief refresher on a couple of aspects of Perl. Perl has the usual notion of true/false. These four values are false;
everything else is true. 'undef' is a special value; it's what Perl gives to a newly declared but uninitialized variable. That means there's this additional dimension of
defined/undefined we have to deal with
33. Boolean operators (or, and)
look at truthiness.
Many times, only invalid value for something is
undef. So can't look at truthiness; must look
at definedness
Quick Perl background
Now, Perl's Boolean operations *only* look at true/false. They don't care about defined/undefined at all, except for how undef is false.
But many times, you don't end up caring about true/false, you care about def/undef
36. $value = $this // $that
defined-or
Now that I've given you that background, now I can explain this great new feature we got in 5.10, called 'defined-or'. It let's you write that code like so.
Which is pretty awesome. Defined-or was my favorite new perl feature of the 2000s
38. my $copy = $orig;
$copy =~ s/swap/stuff/;
Regular expressions are a big part of Perl programming, including substitution style regexps. If you want to apply a substitution to a variable but _not_ change your
original value, you need to do something like this - make a copy, then do the sub on the copy
46. dereferencing
@{ $arrayref }
so, if you've ever worked with references in perl, you've probably done this. a reference is how perl does data abstraction, it's kinda like a pointer (only way safer). this is
how you turn a reference to an array back into the actual array
47. postfix
dereferencing
$arrayref->@*
New syntax for this -- not really *less* punctuation, but different punctuation. I'm not a huge fan, but some people (including former pumpking Rik Signes) really like this.
We added postfix deref in 5.20; it became non-experimental in 5.24
54. 2-arg open
open(IN, '> file');
where as this is open for writing. (and if you wrote this code and called the file handle IN, we can't be friends.)
2 arg is bad, because if 'file' is actually in a variable, and somehow that variable gets a '>' or '<' or '|' in it, unexpected things happen
55. 3-arg open
open($in, '<', 'file');
this is how we write that code these days, the three argument form. here the file name is just used literally, and if it gets one of those punctuation chars in it, you'll get an
error rather than a bad surprise
60. subroutine
signatures
Finally, and I think this is maybe _the_ biggest feature this decade, we've also recently gotten support for subroutine signatures in 5.20
64. sub add ($one, $two) {
return $one + $two;
}
so we don't even have to unpack @_ ourselves! you can even provide default values, validate arguments in the function signature, and all sorts of crazy stuff
Who has started using subroutine signatures? They're still experimental, but hopefully will be non-experimental in 5.26
65. new tools
It's not just language level features, we also have a host of new tools to make it easier to work with Perl
74. advantages
• Solves "vendor Perl lockin" issues
• Install multiple Perls in your home directory
• ... or elsewhere
• Trivially switch from Perl version to Perl version
• Able to install modules without special permissions
• Easy to stay up to date with Perl development
either one of these tools will give you numerous advantages over using the system perl
75. plenv > perlbrew
• Less magic messing around with $PATH
• Can "pin" Perl different ways: globally, per-shell, or per-directory
personally, i'm using plenv these days -- the ability to easily specify a Perl version for a particular project is particularly useful to me
79. local::lib
• Install your own copies of modules
• In your $HOME (so no special permissions needed)
• Can also install per-project modules
• Integrates well with other tools
• Not going to go into how to make it work, but the docs are great!
100. Duck Duck Go
we also have a new search engine here in 2016. it's cool, and it's partially written in Perl
101. Duck Duck Go
!cpanm
The most useful feature, though, is ability to use 'bang searches' to restrict your search to a particular site - this is how you search metacpan
102. speaking of modules...
if you haven't been playing close attention to perl community goings on, there are a few new modules you may have missed
103. JSON::MaybeXS
anybody doing web development these days needs to interact with JSON - using JSON::MaybeXS will make sure that you have a JSON library available, picking the best
one from a number of alternatives
104. Cpanel::JSON::XS
JSON::XS
JSON::PP
here's how the fallback works -- and if you install JSON::MaybeXS and don't have any of these installed, it will require Cpanel::JSON::XS (as long as you have a compiler
to build the XS)
105. Moose
Moo
To get a handle on how we do OOP in Perl these days, you should look into Moose -- and then when you're ready to write some code, you'll probably be able to get
away with dropping down to Moo
108. Plack
But the current standard for web development in Perl is Plack/PSGI. Offers a number of advantages over CGI, and is the basis for all modern Perl web frameworks
109. speaking of Perl websites…
we have quite a few new websites these days, which make it easier to keep up with the current state of things
110. http://cpanratings.perl.org/
one of the problems with cpan is there's just _so_ _much_ _stuff_ there. it can be hard to decide which one of a dozen different modules to use. cpanratings helps with
this problem
111. http://cpanratings.perl.org/
you can see individual reviews, which version they're reviewing, and so on. one downside - because ratings are about a particular version, may not reflect current module
state
118. Perl 5 Porters mailing list summaries!
In a recent development, sawyer has revived the p5p weekly email summary -- excellent if you want to keep up with what's going on with perl5 development but don't
have time to follow the email list yourself
119. http://blogs.perl.org/users/sawyer_x/
and in a recent development, sawyer has revived the p5p weekly email summary -- excellent if you want to keep up with what's going on with perl5 development but
don't have time to follow the email list yourself
120. speaking of Perl community…
finally, you really should consider becoming more actively involved with the perl community, if you're working with (or even just playing with) perl
121. irc.perl.org
irc.perl.org had a *bit* of a bad reputation </understatement> but things have been cleaned up a bunch. there's a documented standards of conduct, abuse is not
tolerated, and it's a good place to get help from experienced perl folk
122. Conferences
& Workshops
& Mongers
(oh my.)
big conferences: YAPC, once a year (or so), in North America, Europe, Asia. Sometimes Brazil, Russia too
workshops: smaller, regional. Pittsburgh, DC-Baltimore, Orlando
perl mongers groups: like MasterCard, we *errywhere* you want to be
125. http://perlweekly.com/
finally, let me give a big shout out to perl weekly, which is a once a week email newsletter and website aggregating perl related news from all over the web
if you're only going to pay attention to one perl thing, perl weekly is your best choice! sign up at perlweekly.com
126. thanks!
thanks to the organizers for accepting my talk, thanks to all of you for attending and participating ...
127. thanks to my employer for giving me the time to write this talk and sending me here to deliver it