The document provides a summary of updates and improvements to the Perl programming language from 2001 to 2017. Some key points include:
- After a period of slow development from 2001-2007, Perl saw a "renaissance" starting in 2010 with regular yearly releases and a predictable development cycle.
- Many language improvements were made, such as improved Unicode support, the defined-or operator, non-destructive regular expressions, and subroutine signatures.
- New tools like Perlbrew, plenv, local::lib, and cpanm were created to more easily install and manage Perl versions and modules.
- The talk encourages using a "modern Perl" approach with new tools rather than relying on the
(Genuine) Escort Service Lucknow | Starting ā¹,5K To @25k with A/C š§š½āā¤ļøāš§š» 89...
Ā
Old Dogs & New Tricks: What's New With Perl5 This Century
1. Old Dogs & New Tricks:
What's New with Perl5 This Century
John SJ Anderson ā Inļ¬nity Interactive ā @genehack
Ohio LinuxFest 2017 ā 29 September 2017
3. Hi I'm John
ā¢ VP Tech, Inļ¬nity 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 decade or so.
5. Perl6 was released!
but this talk is about perl5, so that's the last i'm going to talk about perl6
6. but Perl6 != Perl5
but this talk is about perl5, so that's the last i'm going to talk about perl6
10. 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)
*mention even-odd numbering convention*
11. 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 ļ¬ve year gap there? yeah, those were not great times.
12. 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! ...
14. 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
5.26.0 - 30 May 2017
here are all the releases since 5.12. notice anything?
15. 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
5.26.0 - 30 May 2017
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
16. 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 eļ¬ort -- our
Benevolent Dictator for the Moment, if you will
17. 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
5.26.0 - 30 May 2017
Jesse
Rik
Sawyer
there were three pumpkings involved in this, Jesse Vincent for 5.12 and 5.14, and then Rik Signes for 5.16 thru 5.24, then Sawyer X for 5.26 (which just came out a few
months ago)
18. 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
19. ā¤ Jesse
ā¤ Rik
ā¤ Sawyer
much respect to Jesse, Rik, and Sawyer for the work involved in this, it was *not* a trivial undertaking to start or to keep going.
20. ā¤ 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.
21. 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.
22. ā¤
chromatic
modernperlbooks.com
Writing this book was a tremendous eļ¬ort 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.
23. Many
language
improvements
One of the main beneļ¬ts 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.
24. 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
27. false values: 0, '', ( ), undef
everything else is true
undeļ¬ned values: undef
everything else is deļ¬ned
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
deļ¬ned/undeļ¬ned we have to deal with
28. 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 deļ¬nedness
Quick Perl background
Now, Perl's Boolean operations *only* look at true/false. They don't care about deļ¬ned/undeļ¬ned 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
29. if ( defined($this) ) {
$value = $this
}
else { # use default
$value = $that
}
So that leads to writing code that looks like this... *explain code*
30. $value = defined($this) ? $this : $that
The more idiomatic way of writing that code is to use the ternary operator -- this just does the same thing as the previous slide in a more compact way
31. $value = $this // $that
deļ¬ned-or
Now that I've given you that background, now I can explain this great new feature we got in 5.10, called 'deļ¬ned-or'. It let's you write that code like so.
Which is pretty awesome. Deļ¬ned-or was my favorite new perl feature of the 2000s
32. $this //= 'default'
# much like this, butā¦
$this ||= 'default'
deļ¬ned-or
You can also combine this with assignment, in much the same way you can say ||= for 'or equals'
33. 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
34. (my $copy = $orig) =~ s/swap/stuff/;
and this is just a more idiomatic way to do the same thing.
35. (my $copy = $orig) =~ s/swap/stuff/;
this makes the copy (and the parens are *required*)...
36. (my $copy = $orig) =~ s/swap/stuff/;
and then this applies the sub to the result of the left hand side, which means $copy gets changed and $orig is left unchanged
37. my $copy = $orig =~ s/swap/stuff/r;
non-destructive s///
new in 5.14, we have a new way do this. don't need the parens.
the key here is ...
38. my $copy = $orig =~ s/swap/stuff/r;
non-destructive s///
this 'r' modiļ¬er to the regexp, which makes
42. diamond
<>
This is related to the classic 'diamond' operator, which is used when processing ļ¬les that are passed as arguments on the command line
43. # loop over files from command line
while (<>) {
# do something with each line
}
# call like 'script.pl file1 file2 file3'
using the diamond operator typically looks like this, you'll have a script with this while loop, and then call it with a bunch of ļ¬les on the command line. this will loop over
the lines in ļ¬le1, then ļ¬le2, then ļ¬le3, running the loop body for each one
45. 2-arg open
open(IN, '< file');
this is what we call a 2 arg open call. we're opening a ļ¬le, for reading, and attaching it to a ļ¬le handle called IN
46. 2-arg open
open(IN, '< file');
this thing right here, in front of the ļ¬le name, is how you want to open the ļ¬le. this is open for reading.
47. 2-arg open
open(IN, '> file');
where as this is open for writing. (and if you wrote this code and called the ļ¬le handle IN, we can't be friends.)
2 arg is bad, because if 'ļ¬le' is actually in a variable, and somehow that variable gets a '>' or '<' or '|' in it, unexpected things happen
48. 3-arg open
open($in, '<', 'file');
this is how we write that code these days, the three argument form. here the ļ¬le 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
50. Means that this:
script.pl '> file1'
is gonna be a bad time
So doing something like this will open 'ļ¬le1' for writing, clobbering whatever is there.
53. 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
54. sub add {
my ($one, $two) = @_;
return $one + $two;
}
this is how you might write a simple perl function to add together two numbers. the @_ is a special variable that's used to pass in the arguments for the function.
55. sub add {
my ($one, $two) = @_;
return $one + $two;
}
This bit in the ļ¬rst line is called "unpacking @_", and code like this is at the top of literally almost every Perl function *EVER*
56. sub add ($one, $two) {
return $one + $two;
}
this code does the exact same thing!
57. 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 stuļ¬
Who has started using subroutine signatures? They're still experimental, but hopefully will be non-experimental in 5.26
58. 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
67. 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
68. 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
72. 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!
76. % cpan Git::Wrapper
CPAN: Storable loaded ok (v2.54)
Reading '/Users/genehack/.cpan/Metadata'
Database was generated on Sat, 10 Oct 2015 01:17:02 GMT
Running install for module 'Git::Wrapper'
CPAN: LWP::UserAgent loaded ok (v6.13)
Fetching with LWP:
http://cpan.schatt.com/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz
CPAN: YAML loaded ok (v1.15)
CPAN: Digest::SHA loaded ok (v5.95)
Fetching with LWP:
http://cpan.schatt.com/authors/id/G/GE/GENEHACK/CHECKSUMS
CPAN: Compress::Zlib loaded ok (v2.068)
Checksum for /Users/genehack/.cpan/sources/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz ok
tmp-47326 for tmp-47326: No such file or directory at /opt/plenv/versions/5.23.2/lib/perl5/5.23.2/CPAN/
Distribution
.pm line 468.
CPAN: File::Temp loaded ok (v0.2304)
CPAN: CPAN::Meta::Requirements loaded ok (v2.133)
CPAN: Parse::CPAN::Meta loaded ok (v1.4417)
CPAN: CPAN::Meta loaded ok (v2.150005)
CPAN: Module::CoreList loaded ok (v5.20150820)
Configuring G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz with Makefile.PL
Locating bin:git... found at /opt/git/bin/git.
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Git::Wrapper
Writing MYMETA.yml and MYMETA.json
this is the output from using the default 'cpan' client to install something.
77. GENEHACK/Git-Wrapper-0.045.tar.gz [17/1516]
/opt/plenv/versions/5.23.2/bin/perl5.23.2 Makefile.PL -- OK
Running make for G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz
cp lib/Git/Wrapper/File/RawModification.pm blib/lib/Git/Wrapper/File/RawModification.pm
cp lib/Git/Wrapper.pm blib/lib/Git/Wrapper.pm
cp lib/Git/Wrapper/Statuses.pm blib/lib/Git/Wrapper/Statuses.pm
cp lib/Git/Wrapper/Exception.pm blib/lib/Git/Wrapper/Exception.pm
cp lib/Git/Wrapper/Log.pm blib/lib/Git/Wrapper/Log.pm
cp lib/Git/Wrapper/Status.pm blib/lib/Git/Wrapper/Status.pm
Manifying 6 pod documents
GENEHACK/Git-Wrapper-0.045.tar.gz
/usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 "/opt/plenv/versions/5.23.2/bin/perl5.23.2" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "und
ef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-load.t ............... 1/6 # Testing Git::Wrapper 0.045
t/00-load.t ............... ok
t/author-err.t ............ skipped: these tests are for testing by the author
t/basic.t ................. # Testing git version: 2.5.2
t/basic.t ................. ok
t/git_binary.t ............ ok
t/parse_args.t ............ ok
t/path_class.t ............ # Testing git version: 2.5.2
t/path_class.t ............ ok
t/release-pod-coverage.t .. skipped: these tests are for release candidate testing
t/release-pod-syntax.t .... skipped: these tests are for release candidate testing
All tests successful.
Files=8, Tests=67, 1 wallclock secs ( 0.04 usr 0.02 sys + 0.39 cusr 0.31 csys = 0.76 CPU)
Result: PASS
GENEHACK/Git-Wrapper-0.045.tar.gz
and this is more of the output...
79. % cpanm Git::Wrapper
--> Working on Git::Wrapper
Fetching http://www.cpan.org/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz ... OK
Configuring Git-Wrapper-0.045 ... OK
Building and testing Git-Wrapper-0.045 ... OK
Successfully installed Git-Wrapper-0.045
this is the output from cpanm installing the same thing
80. % cpanm Git::Wrapper
--> Working on Git::Wrapper
Fetching http://www.cpan.org/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz ... OK
Configuring Git-Wrapper-0.045 ... OK
Building and testing Git-Wrapper-0.045 ... OK
Successfully installed Git-Wrapper-0.045
this is the output from cpanm installing the same thing
86. pinto
Another tool, pinto, let's you have your own private CPAN within your organization. Great if you have a number of devs working on things independently, because folks
can do releases, make modules available, without having to build system packages
87. Your very own
private CPAN
Another tool, pinto, let's you have your own private CPAN within your organization. Great if you have a number of devs working on things independently, because folks
can do releases, make modules available, without having to build system packages
96. Duck Duck Go
we also have a new search engine here in 2016. it's cool, and it's partially written in Perl
97. 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
98. 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
99. 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
100. 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)
101. 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
104. Plack
But the current standard for web development in Perl is Plack/PSGI. Oļ¬ers a number of advantages over CGI, and is the basis for all modern Perl web frameworks
105. 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
106. 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
107. 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
108. http://cpanratings.perl.org/
one of the problems with cpan is there's just _so_ _much_ _stuļ¬_ there. it can be hard to decide which one of a dozen diļ¬erent modules to use. cpanratings helps with
this problem
109. 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 reļ¬ect current module
state
116. % cpanm Git::Wrapper
--> Working on Git::Wrapper
Fetching http://www.cpan.org/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz ... OK
Configuring Git-Wrapper-0.045 ... OK
Building and testing Git-Wrapper-0.045 ... OK
Successfully installed Git-Wrapper-0.045
117. % cpanm Git::Wrapper
--> Working on Git::Wrapper
Fetching http://www.cpan.org/authors/id/G/GE/GENEHACK/Git-Wrapper-0.045.tar.gz ... OK
Configuring Git-Wrapper-0.045 ... OK
Building and testing Git-Wrapper-0.045 ... OK
Successfully installed Git-Wrapper-0.045
122. speaking of Perl communityā¦
ļ¬nally, you really should consider becoming more actively involved with the perl community, if you're working with (or even just playing with) perl
123. ļ¬nally, you really should consider becoming more actively involved with the perl community, if you're working with (or even just playing with) perl
124. 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
128. http://perlweekly.com/
ļ¬nally, 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
129. thanks!
thanks to the organizers for accepting my talk, thanks to all of you for attending and participating ...
130. thanks to my employer for giving me the time to write this talk and sending me here to deliver it