SlideShare a Scribd company logo
London Perl Workshop 2016
Modern Perl
Catch-Up
London Perl Workshop 2016
Modern Perl Catch-Up
●
New things in Perl that you might have missed
●
Haven't we done this before?
●
"Modern Core Perl" December 2011
●
This is a sequel
London Perl Workshop 2016
Perl Releases
●
Perl is released annually
●
In the spring
●
Even-numbered versions are production releases
– 5.22, 5.24, 5.26
●
Odd-numbered versions are development releases
– 5.21, 5.23, 5.25
●
5.25 will become 5.26
London Perl Workshop 2016
Perl Support
●
Perl releases are officially supported for two
years
● perldoc perlpolicy
●
Currently 5.22 and 5.24
●
Limited support for older versions
●
Longer support from vendors
London Perl Workshop 2016
Update Your Perl
●
Using the system Perl is a bad idea
●
Often out of date
● perlbrew and plenv
London Perl Workshop 2016
5.16
London Perl Workshop 2016
5.16
●
5.16.0 - 20 May 2012
●
5.16.1 - 08 Aug 2012
●
5.16.2 - 01 Nov 2012
●
5.16.3 - 11 Mar 2013
London Perl Workshop 2016
5.16 Features
● __SUB__
●
Fold case
●
Devel::DProf removed
●
perlexperiment
●
perlootut
●
Old OO docs removed
●
Unicode 6.1
London Perl Workshop 2016
__SUB__
●
New special source code token
● Like __PACKAGE__, __FILE__ and __LINE__
●
Returns a reference to the current subroutine
●
Easier to write recursive subroutines
London Perl Workshop 2016
Recursive without __SUB__
sub fib {
my ($n) = @_;
return 1 if $n <= 2;
return fib($n - 1) + fib($n - 2);
}
London Perl Workshop 2016
Recursive with __SUB__
sub fib {
my ($n) = @_;
return 1 if $n <= 2;
return __SUB__->($n - 1) +
__SUB__->($n - 2);
}
London Perl Workshop 2016
Recursive with __SUB__
sub fib {
my ($n) = @_;
return 1 if $n <= 2;
return __SUB__->($n - 1) +
__SUB__->($n - 2);
}
London Perl Workshop 2016
Fold Case
● lc($this) eq lc($that)
●
Unicode complicates everything
●
Lower-case comparisons can fail
●
As can upper-case comparisons
●
"Fold-case" is guaranteed to work
● fc($this) eq fc($that)
● Also F (like L and U)
London Perl Workshop 2016
Devel::DProf Removed
●
Devel::DProf was an old profiling tool
●
Few people know how to use it
●
We're better off without it
●
Devel::NYTProf is much better
London Perl Workshop 2016
perldoc perlexperiment
●
New documentation page
●
Lists the experiments in the current version of
Perl
– Vital to use the right version
● Compare perldoc experimental
London Perl Workshop 2016
perldoc perlootut
●
New OO tutorial
●
Improvement on old version
●
Up to date
●
Covers OO frameworks
– Moose, Moo, Class::Accessor, Class::Tiny, Role::Tiny
●
So consider those the "approved" list of OO
frameworks
London Perl Workshop 2016
Old OO docs removed
●
Outdated OO documentation removed
●
perlboot (basic OO tutorial)
●
perltoot (Tom's OO tutorial)
●
perlbot (bag of object tricks)
●
perlootut replaces all of these
London Perl Workshop 2016
Unicode 6.1
●
Unicode complicates everything!
●
http://www.unicode.org/versions/Unicode6.1.0
●
"This latest version adds characters to support
additional languages of China, other Asian
countries, and Africa. It also addresses
educational needs in the Arabic-speaking world.
A total of 732 new characters have been added."
London Perl Workshop 2016
5.18
London Perl Workshop 2016
5.18
●
5.18.0 - 18 May 2013
●
5.18.1 - 12 Aug 2013
●
5.18.2 - 06 Jan 2013
●
5.18.3 - 01 Oct 2014
●
5.18.4 - 01 Oct 2014
London Perl Workshop 2016
5.18 Features
● no warnings experimental::foo
●
Hash rework
●
Lexical subroutines
●
Smartmatch is experimental
● Lexical $_ is experimental
● $/ = $n reads $n characters (not bytes)
● qw(...) needs extra parentheses
●
Unicode 6.2
London Perl Workshop 2016
no warnings experimental::foo
●
New "warnings" category - experimental
●
Warns if you use experimental features
● no warnings experimental::foo
●
"Don't warn me that I'm using experimental
feature 'foo'"
●
"I know what I'm doing here!"
London Perl Workshop 2016
Hash Rework
●
Big change in the way hashes are implemented
●
Hash ordering is even more random
●
Random seed in hashing algorithm
● keys (and values, etc) returns different order
each run
●
Algorithmic complexity attacks
London Perl Workshop 2016
Example
$ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h'
onethreetwo
$ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h'
threetwoone
$ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h'
threetwoone
$ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h'
threeonetwo
London Perl Workshop 2016
Previously
●
With earlier versions, the same hash would
return the keys in the same order each time
●
Now you can't rely on that
●
Exposes weaknesses in tests
●
Careful testing required!
London Perl Workshop 2016
Lexical Subroutines
●
Experimental feature
● no warnings
experimental::lexical_subs
●
Truly private subroutines
●
Only visible within your lexical scope
● state sub foo { ... }
● my sub bar { ... }
London Perl Workshop 2016
state vs my
●
Similar to variable declarations
● my subroutines are recreated each time their scope is
executed
● state subroutines are created once
● state subroutines are slightly faster
● my subroutines are required for closures
● Also our for access to a global subroutine of the same
name
London Perl Workshop 2016
Private Subroutines
● We name private subroutines with leading _
● sub _dont_run_this { ... }
●
"Please don't run this"
●
We can now enforce this
● state sub _cant_run_this { ... }
●
Only visible within current lexical scope
London Perl Workshop 2016
Smartmatch is Experimental
●
Smartmatch is confusing
●
Smartmatch has changed a few times
●
Smartmatch should probably be avoided
●
Smartmatch is experimental
● no warnings
experimental::smartmatch
● Warns on ~~, given and when
London Perl Workshop 2016
Smartmatch
“Smart match, added in v5.10.0 and significantly revised
in v5.10.1, has been a regular point of complaint.
Although there are a number of ways in which it is
useful, it has also proven problematic and confusing for
both users and implementors of Perl. There have been a
number of proposals on how to best address the
problem. It is clear that smartmatch is almost certainly
either going to change or go away in the future. Relying
on its current behavior is not recommended.”
London Perl Workshop 2016
Lexical $_ is Experimental
●
Introduced in 5.10
●
"it has caused much confusion with no obvious
solution"
● no warnings
experimental::lexical_topic
●
Spoilers: Removed in 5.24
London Perl Workshop 2016
$/ = $n Reads $n Characters
● Setting $/ to a reference to an integer
●
(Previously) Reads that number of bytes
●
(Now) Reads that number of characters
●
This is almost certainly what you want
●
Unicode complicates everything
London Perl Workshop 2016
qw(...) Needs Extra Parentheses
●
Correcting a parsing bug
● foreach qw(foo bar baz) { ... }
●
Perl previously added the missing parentheses
●
Now it doesn't
● foreach (qw(foo bar baz)) { ... }
London Perl Workshop 2016
Unicode 6.2
●
Unicode complicates everything!
●
http://www.unicode.org/versions/Unicode6.2.0
●
"Version 6.2 of the Unicode Standard is a special
release dedicated to the early publication of the
newly encoded Turkish lira sign."
London Perl Workshop 2016
5.20
London Perl Workshop 2016
5.20
●
5.20.0 - 27 May 2014
●
5.20.1 - 14 Sep 2014
●
5.20.2 - 14 Feb 2015
●
5.20.3 - 12 Sep 2015
London Perl Workshop 2016
5.20 Features
●
Subroutine signatures (experimental)
● %hash{...} and %array[...] slices
●
Postfix dereferencing (experimental)
●
Unicode 6.3
London Perl Workshop 2016
Subroutine Signatures
●
Subroutines can now have a signature
● sub foo ($bar, $baz) { ... }
● use feature 'signatures'
●
Experimental
● no warnings
experimental::signatures
London Perl Workshop 2016
Mandatory Parameters
● sub foo ($bar, $baz) { ... }
●
Checks the number of parameters
●
Throws exception if the wrong number
● Assigns parameters to $bar and $baz
London Perl Workshop 2016
Unnamed Parameter
●
Parameters can be unnamed
● Use $ without a name
● sub foo ($bar, $, $baz) { ... }
●
Must pass three parameters
●
Second parameter is not assigned to a variable
● All parameters still in @_
London Perl Workshop 2016
Optional Parameters
●
Make parameters optional by giving them a
default
● sub foo ($bar, $baz = 0) { ... }
●
Call with one or two parameters
● $baz set to 0 by default
London Perl Workshop 2016
Slurpy Parameters
●
'Slurpy' parameters follow postional parameters
●
Assign them to an array
● sub foo ($bar, @baz) { ... }
● foo('a', 'b', 'c');
●
Or a hash
● sub foo ($bar, %baz) { ... }
● foo('a', 'b', 'c');
● foo('a', b => 'c');
London Perl Workshop 2016
%hash{...} and %array[...]
Slices
●
Old array slices
● @slice = @array[1, 3..5]
●
Returns four elements from the array
●
Also with hashes
● @slice = @hash{'foo', 'bar', 'baz'}
●
Returns three values from the hash
London Perl Workshop 2016
New Hash Slices
● New %h{...} slice syntax
● %subhash =
%hash{'foo', 'bar', 'baz'}
●
Returns three key/value pairs
●
Also with arrays
● @slice = %array[1, 3..5]
●
Returns four index/element pairs
London Perl Workshop 2016
Postfix Dereferencing
● no warnings experimental::postderef
●
New syntax for dereferencing
●
Follows left-to-right rules throughout
London Perl Workshop 2016
Postfix vs Prefix
● $sref->$*; # same as ${ $sref }
● $aref->@*; # same as @{ $aref }
● $href->%*; # same as %{ $href }
● $cref->&*; # same as &{ $cref }
● $gref->**; # same as *{ $gref }
London Perl Workshop 2016
Left to Right Throughout
●
Old style
● @arr = @{$r->{foo}[0]{bar}}
●
New style
● @arr = $r->{foo}[0]{bar}->@*
London Perl Workshop 2016
Unicode 6.3
●
Unicode complicates everything!
●
http://www.unicode.org/versions/Unicode6.3.0
●
"Version 6.3 of the Unicode Standard is a special
release focused on delivering significantly
improved bidirectional behavior."
London Perl Workshop 2016
5.22
London Perl Workshop 2016
5.22
●
5.22.0 - 01 Jun 2015
●
5.22.1 - 13 Dec 2015
●
5.22.2 - 29 Apr 2016
London Perl Workshop 2016
5.22 Features
●
New bitwise operators
●
Double diamond operator
● New regex boundaries b{...}
● New /n option on regexes
●
Unicode 7.0
● Omitting % and & on hash and array names now
an error
London Perl Workshop 2016
5.22 Features (cont)
● defined(@array) and defined(%hash) now
fatal error
● %hash->{$key} and @array->[$idx] now fatal
errors
●
perlunicook
●
find2perl, a2p, s2p removed
●
CGI removed
●
Module::Build removed
London Perl Workshop 2016
New Bitwise Operators
●
Old bitwise operators
● ~, &, |, ^
●
Expect numbers as operands
●
"Work" on strings too
●
No numeric/string differentiation
London Perl Workshop 2016
New Bitwise Operators
● use feature 'bitwise';
● no warnings
'experimental::bitwise';
● Or use experimental 'bitwise';
●
Old operators are always numeric
●
New string bitwise operators
● ~., &., |., ^.
London Perl Workshop 2016
Double Diamond Operator
● <<>>
● Like <>
● Uses three-arg open()
● All elements of @ARGV treated as filenames
● |foo will no longer work
London Perl Workshop 2016
New Regex Boundaries
● Extensions to b
● b{wb} - Word boundary
– Like b but cleverer about punctuation within words
● b{sb} - Sentence boundary
● b{gcb} - Grapheme cluster boundary
– Unicode complicates everything!
London Perl Workshop 2016
/n Option on Regexes
● New option for m/.../ and s/.../.../
●
Turns off call capturing
● /(w+)/ - fills in $1
● /(w+)/n - doesn't
● See also (?:w+)
London Perl Workshop 2016
Unicode 7.0
●
Unicode complicates everything!
●
http://www.unicode.org/versions/Unicode7.0.0
●
"Unicode 7.0 adds a total of 2,834 characters,
encompassing 23 new scripts and many new
symbols, as well as character additions to many
existing scripts"
London Perl Workshop 2016
Unicode 7.0
●
Two newly adopted currency symbols: the manat, used in
Azerbaijan, and the ruble, used in Russia and other countries
●
Pictographic symbols (including many emoji), geometric
symbols, arrows, and ornaments originating from the
Wingdings and Webdings sets
●
Twenty-three new lesser-used and historic scripts extending
support for written languages of North America, China, India,
other Asian countries, and Africa
●
Letters used in Teuthonista and other transcriptional systems,
and a new notational set, Duployan
London Perl Workshop 2016
Omitting % and @ on Hash and Array
Names
●
You used to be able to omit sigils in some
circumstances
●
Very stupid thing to do
●
Deprecation warning since 5.000 (1994!)
●
Now a fatal error
London Perl Workshop 2016
defined(@array) and
defined(%hash) now Fatal Errors
●
Another parser bug fixed
●
Deprecated since 5.6.1
●
Deprecation warning since 5.16
●
Now a fatal error
London Perl Workshop 2016
%hash->{$key} and @array-
>[$idx] now Fatal Errors
●
Bet you didn't know you could do that
●
Now you can't
●
Deprecated since "before 5.8"
●
Now a fatal error
London Perl Workshop 2016
perlunicook
●
New cookbook of Unicode recipes
●
By Tom Christiansen
●
Well worth reading
●
If you think you don't care about Unicode,
you're wrong
●
Unicode complicates everything
London Perl Workshop 2016
find2perl, a2p, s2p Removed
●
Old programs that converted from standard
Unix utilities
●
No-one had used them for years
●
No-one had maintained them for years
●
No-one cares they're gone
London Perl Workshop 2016
CGI Removed
●
Contentious
●
CGI is a terrible way to write web applications
●
Including CGI.pm with Perl was seen as an
endorsement
●
Best to remove it
●
Use PSGI/Plack instead
London Perl Workshop 2016
Module::Build Removed
●
Written as a replacement for
ExtUtils::MakeMaker
●
Pure Perl
● Didn't use make
●
Cross-platform
●
Failed experiment
London Perl Workshop 2016
5.24
London Perl Workshop 2016
5.24
●
5.24.0 - 09 May 2016
London Perl Workshop 2016
5.24 Features
●
Postfix dereferencing no longer experimental
●
Unicode 8.0
● b{lb}
●
Shebang redirects to Perl6
●
autoderef removed
London Perl Workshop 2016
Postfix Dereferecing
●
Added in 5.20
●
No longer experimental
London Perl Workshop 2016
Unicode 8.0
●
Unicode complicates everything!
●
http://www.unicode.org/versions/Unicode8.0.0
●
"Unicode 8.0 adds a total of 7,716 characters,
encompassing six new scripts and many new
symbols, as well as character additions to
several existing scripts."
London Perl Workshop 2016
Unicode 8.0
●
A set of lowercase Cherokee syllables, forming case pairs with the
existing Cherokee characters
●
A large collection of CJK unified ideographs
●
Emoji symbols and symbol modifiers for implementing skin tone
diversity
●
Georgian lari currency symbol
●
Letters to support the Ik language in Uganda, Kulango in the Côte
d’Ivoire, and other languages of Africa
●
The Ahom script for support of the Tai Ahom language in India
●
Arabic letters to support Arwi—the Tamil language written in the Arabic
script
London Perl Workshop 2016
b{lb}
●
New regex boundary
●
Matches a (potential) lib break
●
Place where you could break a line
●
Unicode property
●
See also Unicode::Linebreak
London Perl Workshop 2016
Shebang Redirects to Perl 6
●
Perl will start another program given in the
shebang
● E.g. #!/usr/bin/ruby
●
Only if the path doesn't contain "perl"
●
Now works for "perl6" too
London Perl Workshop 2016
Auto-deref Removed
●
Added in 5.14
●
Array and hash functions work on references
● push @$arr_ref vs push $arr_ref
● keys %$hash_ref vs keys %$hash_ref
●
"Deemed unsuccessful"
London Perl Workshop 2016
5.26
London Perl Workshop 2016
Perl 5.26
●
Released next spring
●
Perl 5.25 is dev branch
●
A sneak peek
London Perl Workshop 2016
Perl 5.26
●
Lexical subroutines no longer experimental
●
Unicode 9.0.0
● Declare references to variables - my $x
London Perl Workshop 2016
Staying Up To
Date
London Perl Workshop 2016
Staying Up To Date
●
How do you know a new version of Perl has
been released?
●
How do you know what is in a new release of
Perl?
London Perl Workshop 2016
Keep Up To Date With Perl News
●
@perlfoundation
●
Reddit
●
Perl Weekly
London Perl Workshop 2016
@perlfoundation
●
The Perl Foundation Twitter account
●
~7,000 followers
●
Run by volunteers
●
Tries to be first with Perl news
London Perl Workshop 2016
Reddit
●
Perl subreddit
●
http://reddit.com/r/perl
●
Links to interesting Perl articles/announcements
●
Also help students with their Perl homework
London Perl Workshop 2016
Perl Weekly
●
Weekly Perl email
●
Links to interesting Perl articles/announcements
●
Curated by humans
●
Web feed
●
Highly recommended
London Perl Workshop 2016
What Is In The New Release?
● Read the perldelta man page
●
Included with every Perl release
●
Older versions available too
London Perl Workshop 2016
Conclusion
London Perl Workshop 2016
Conclusion
●
Perl has an annual release cycle
●
Interesting/useful changes in each release
●
Worth keeping up to date
●
A reason to upgrade?
London Perl Workshop 2016
Questions?
●
Any questions?
●
Coffee break
London Perl Workshop 2016
Advert
●
Magnum Solutions Ltd
●
Perl Training
●
Perl Development
●
Code Review
●
Design Review
●
dave@mag-sol.com
London Perl Workshop 2016

More Related Content

PDF
Modern Perl for Non-Perl Programmers
PDF
Modern Web Development with Perl
PDF
Modern Perl for the Unfrozen Paleolithic Perl Programmer
ODP
Getting started with Perl XS and Inline::C
ODP
Aura for PHP at Fossmeet 2014
PDF
Yapc::NA::2009 - Command Line Perl
PDF
Inside the JVM - Follow the white rabbit!
PPTX
Doctrine 2.0 Enterprise Persistence Layer for PHP
Modern Perl for Non-Perl Programmers
Modern Web Development with Perl
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Getting started with Perl XS and Inline::C
Aura for PHP at Fossmeet 2014
Yapc::NA::2009 - Command Line Perl
Inside the JVM - Follow the white rabbit!
Doctrine 2.0 Enterprise Persistence Layer for PHP

What's hot (20)

PDF
CLI, the other SAPI
PDF
PHP 8.1 - What's new and changed
PPTX
Modern Perl for the Unfrozen Paleolithic Perl Programmer
PDF
#Pharo Days 2016 Data Formats and Protocols
PDF
Introduction to reactive programming & ReactiveCocoa
PDF
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
PDF
Server Side Swift
PPT
Introduction to Javascript
PPTX
Optimizing a large angular application (ng conf)
PDF
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
PDF
LINQ Inside
PDF
Productive Programming in Java 8 - with Lambdas and Streams
PDF
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
PDF
Lambdas and Streams Master Class Part 2
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
PDF
Get your teeth into Plack
PPTX
Java script – basic auroskills (2)
PDF
Functional Programming for Busy Object Oriented Programmers
PDF
PHP 7.1 : elegance of our legacy
PPTX
Zephir - A Wind of Change for writing PHP extensions
CLI, the other SAPI
PHP 8.1 - What's new and changed
Modern Perl for the Unfrozen Paleolithic Perl Programmer
#Pharo Days 2016 Data Formats and Protocols
Introduction to reactive programming & ReactiveCocoa
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
Server Side Swift
Introduction to Javascript
Optimizing a large angular application (ng conf)
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
LINQ Inside
Productive Programming in Java 8 - with Lambdas and Streams
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Lambdas and Streams Master Class Part 2
Diving into HHVM Extensions (PHPNW Conference 2015)
Get your teeth into Plack
Java script – basic auroskills (2)
Functional Programming for Busy Object Oriented Programmers
PHP 7.1 : elegance of our legacy
Zephir - A Wind of Change for writing PHP extensions
Ad

Viewers also liked (20)

PDF
Freeing Tower Bridge
ODP
Object-Oriented Programming with Perl and Moose
PDF
Matt's PSGI Archive
PPTX
A study of the local tribes of Assam - Bodo under ISA by the students of SBGJ
PPTX
Conflict in Assam
PPTX
Indian tribals by bikrant roy
PPTX
Assam
PPTX
A study of the local tribes of Assam and Egypt under ISA by the students of S...
ODP
Moose (Perl 5)
PPS
Web Development in Perl
PDF
Mojolicious. The web in a box!
PDF
Introduction to OO Perl with Moose
PDF
Medium Perl
PDF
Perl hosting for beginners - Cluj.pm March 2013
KEY
Web Operations and Perl kansai.pm#14
ODP
Modern Web Development with Perl
ODP
Introduction to Web Programming with Perl
ODP
Database Programming with Perl and DBIx::Class
PPT
Aasam The State
PPTX
Assam ppt
Freeing Tower Bridge
Object-Oriented Programming with Perl and Moose
Matt's PSGI Archive
A study of the local tribes of Assam - Bodo under ISA by the students of SBGJ
Conflict in Assam
Indian tribals by bikrant roy
Assam
A study of the local tribes of Assam and Egypt under ISA by the students of S...
Moose (Perl 5)
Web Development in Perl
Mojolicious. The web in a box!
Introduction to OO Perl with Moose
Medium Perl
Perl hosting for beginners - Cluj.pm March 2013
Web Operations and Perl kansai.pm#14
Modern Web Development with Perl
Introduction to Web Programming with Perl
Database Programming with Perl and DBIx::Class
Aasam The State
Assam ppt
Ad

Similar to Modern Perl Catch-Up (20)

PDF
Modern Core Perl
PDF
Introducing perl6
PPT
2016年のPerl (Long version)
PDF
Modern Perl for the Unfrozen Paleolithic Perl Programmer
PDF
Old Dogs & New Tricks: What's New With Perl5 This Century
PDF
Old Dogs & New Tricks: What's New with Perl5 This Century
ODP
Whatsnew in-perl
PDF
Perl 5.10
ODP
Introduction to Modern Perl
PPTX
Unit 1-introduction to perl
PDF
Introduction to Perl
ODP
Introduction to Perl - Day 1
PDF
Perl6 for-beginners
PDF
Perl 5.16 new features
PDF
Cs3430 lecture 15
ODP
What's new in Perl 5.10?
PPT
Perl Development (Sample Courseware)
PDF
Old Dogs & New Tricks: What's New with Perl5 This Century
PPTX
Perl bhargav
ODP
Introduction to Perl
Modern Core Perl
Introducing perl6
2016年のPerl (Long version)
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Old Dogs & New Tricks: What's New With Perl5 This Century
Old Dogs & New Tricks: What's New with Perl5 This Century
Whatsnew in-perl
Perl 5.10
Introduction to Modern Perl
Unit 1-introduction to perl
Introduction to Perl
Introduction to Perl - Day 1
Perl6 for-beginners
Perl 5.16 new features
Cs3430 lecture 15
What's new in Perl 5.10?
Perl Development (Sample Courseware)
Old Dogs & New Tricks: What's New with Perl5 This Century
Perl bhargav
Introduction to Perl

More from Dave Cross (20)

PDF
Measuring the Quality of Your Perl Code
PDF
Apollo 11 at 50 - A Simple Twitter Bot
PDF
Monoliths, Balls of Mud and Silver Bullets
PPTX
The Professional Programmer
PDF
I'm A Republic (Honest!)
PDF
Web Site Tune-Up - Improve Your Googlejuice
PDF
Modern Perl Web Development with Dancer
PDF
Error(s) Free Programming
PDF
Improving Dev Assistant
PDF
Conference Driven Publishing
PDF
Conference Driven Publishing
PDF
TwittElection
PDF
Perl in the Internet of Things
PDF
Return to the Kingdom of the Blind
PDF
Github, Travis-CI and Perl
PDF
The Kingdom of the Blind
PDF
Matt's PSGI Archive
ODP
Perl Training
ODP
Perl Masons
ODP
Watching the Press
Measuring the Quality of Your Perl Code
Apollo 11 at 50 - A Simple Twitter Bot
Monoliths, Balls of Mud and Silver Bullets
The Professional Programmer
I'm A Republic (Honest!)
Web Site Tune-Up - Improve Your Googlejuice
Modern Perl Web Development with Dancer
Error(s) Free Programming
Improving Dev Assistant
Conference Driven Publishing
Conference Driven Publishing
TwittElection
Perl in the Internet of Things
Return to the Kingdom of the Blind
Github, Travis-CI and Perl
The Kingdom of the Blind
Matt's PSGI Archive
Perl Training
Perl Masons
Watching the Press

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Modernizing your data center with Dell and AMD
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Building Integrated photovoltaic BIPV_UPV.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
Teaching material agriculture food technology
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)
Modernizing your data center with Dell and AMD
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

Modern Perl Catch-Up

  • 1. London Perl Workshop 2016 Modern Perl Catch-Up
  • 2. London Perl Workshop 2016 Modern Perl Catch-Up ● New things in Perl that you might have missed ● Haven't we done this before? ● "Modern Core Perl" December 2011 ● This is a sequel
  • 3. London Perl Workshop 2016 Perl Releases ● Perl is released annually ● In the spring ● Even-numbered versions are production releases – 5.22, 5.24, 5.26 ● Odd-numbered versions are development releases – 5.21, 5.23, 5.25 ● 5.25 will become 5.26
  • 4. London Perl Workshop 2016 Perl Support ● Perl releases are officially supported for two years ● perldoc perlpolicy ● Currently 5.22 and 5.24 ● Limited support for older versions ● Longer support from vendors
  • 5. London Perl Workshop 2016 Update Your Perl ● Using the system Perl is a bad idea ● Often out of date ● perlbrew and plenv
  • 7. London Perl Workshop 2016 5.16 ● 5.16.0 - 20 May 2012 ● 5.16.1 - 08 Aug 2012 ● 5.16.2 - 01 Nov 2012 ● 5.16.3 - 11 Mar 2013
  • 8. London Perl Workshop 2016 5.16 Features ● __SUB__ ● Fold case ● Devel::DProf removed ● perlexperiment ● perlootut ● Old OO docs removed ● Unicode 6.1
  • 9. London Perl Workshop 2016 __SUB__ ● New special source code token ● Like __PACKAGE__, __FILE__ and __LINE__ ● Returns a reference to the current subroutine ● Easier to write recursive subroutines
  • 10. London Perl Workshop 2016 Recursive without __SUB__ sub fib { my ($n) = @_; return 1 if $n <= 2; return fib($n - 1) + fib($n - 2); }
  • 11. London Perl Workshop 2016 Recursive with __SUB__ sub fib { my ($n) = @_; return 1 if $n <= 2; return __SUB__->($n - 1) + __SUB__->($n - 2); }
  • 12. London Perl Workshop 2016 Recursive with __SUB__ sub fib { my ($n) = @_; return 1 if $n <= 2; return __SUB__->($n - 1) + __SUB__->($n - 2); }
  • 13. London Perl Workshop 2016 Fold Case ● lc($this) eq lc($that) ● Unicode complicates everything ● Lower-case comparisons can fail ● As can upper-case comparisons ● "Fold-case" is guaranteed to work ● fc($this) eq fc($that) ● Also F (like L and U)
  • 14. London Perl Workshop 2016 Devel::DProf Removed ● Devel::DProf was an old profiling tool ● Few people know how to use it ● We're better off without it ● Devel::NYTProf is much better
  • 15. London Perl Workshop 2016 perldoc perlexperiment ● New documentation page ● Lists the experiments in the current version of Perl – Vital to use the right version ● Compare perldoc experimental
  • 16. London Perl Workshop 2016 perldoc perlootut ● New OO tutorial ● Improvement on old version ● Up to date ● Covers OO frameworks – Moose, Moo, Class::Accessor, Class::Tiny, Role::Tiny ● So consider those the "approved" list of OO frameworks
  • 17. London Perl Workshop 2016 Old OO docs removed ● Outdated OO documentation removed ● perlboot (basic OO tutorial) ● perltoot (Tom's OO tutorial) ● perlbot (bag of object tricks) ● perlootut replaces all of these
  • 18. London Perl Workshop 2016 Unicode 6.1 ● Unicode complicates everything! ● http://www.unicode.org/versions/Unicode6.1.0 ● "This latest version adds characters to support additional languages of China, other Asian countries, and Africa. It also addresses educational needs in the Arabic-speaking world. A total of 732 new characters have been added."
  • 19. London Perl Workshop 2016 5.18
  • 20. London Perl Workshop 2016 5.18 ● 5.18.0 - 18 May 2013 ● 5.18.1 - 12 Aug 2013 ● 5.18.2 - 06 Jan 2013 ● 5.18.3 - 01 Oct 2014 ● 5.18.4 - 01 Oct 2014
  • 21. London Perl Workshop 2016 5.18 Features ● no warnings experimental::foo ● Hash rework ● Lexical subroutines ● Smartmatch is experimental ● Lexical $_ is experimental ● $/ = $n reads $n characters (not bytes) ● qw(...) needs extra parentheses ● Unicode 6.2
  • 22. London Perl Workshop 2016 no warnings experimental::foo ● New "warnings" category - experimental ● Warns if you use experimental features ● no warnings experimental::foo ● "Don't warn me that I'm using experimental feature 'foo'" ● "I know what I'm doing here!"
  • 23. London Perl Workshop 2016 Hash Rework ● Big change in the way hashes are implemented ● Hash ordering is even more random ● Random seed in hashing algorithm ● keys (and values, etc) returns different order each run ● Algorithmic complexity attacks
  • 24. London Perl Workshop 2016 Example $ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h' onethreetwo $ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h' threetwoone $ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h' threetwoone $ perl -E'%h=(one=>1,two=>2,three=>3); say keys %h' threeonetwo
  • 25. London Perl Workshop 2016 Previously ● With earlier versions, the same hash would return the keys in the same order each time ● Now you can't rely on that ● Exposes weaknesses in tests ● Careful testing required!
  • 26. London Perl Workshop 2016 Lexical Subroutines ● Experimental feature ● no warnings experimental::lexical_subs ● Truly private subroutines ● Only visible within your lexical scope ● state sub foo { ... } ● my sub bar { ... }
  • 27. London Perl Workshop 2016 state vs my ● Similar to variable declarations ● my subroutines are recreated each time their scope is executed ● state subroutines are created once ● state subroutines are slightly faster ● my subroutines are required for closures ● Also our for access to a global subroutine of the same name
  • 28. London Perl Workshop 2016 Private Subroutines ● We name private subroutines with leading _ ● sub _dont_run_this { ... } ● "Please don't run this" ● We can now enforce this ● state sub _cant_run_this { ... } ● Only visible within current lexical scope
  • 29. London Perl Workshop 2016 Smartmatch is Experimental ● Smartmatch is confusing ● Smartmatch has changed a few times ● Smartmatch should probably be avoided ● Smartmatch is experimental ● no warnings experimental::smartmatch ● Warns on ~~, given and when
  • 30. London Perl Workshop 2016 Smartmatch “Smart match, added in v5.10.0 and significantly revised in v5.10.1, has been a regular point of complaint. Although there are a number of ways in which it is useful, it has also proven problematic and confusing for both users and implementors of Perl. There have been a number of proposals on how to best address the problem. It is clear that smartmatch is almost certainly either going to change or go away in the future. Relying on its current behavior is not recommended.”
  • 31. London Perl Workshop 2016 Lexical $_ is Experimental ● Introduced in 5.10 ● "it has caused much confusion with no obvious solution" ● no warnings experimental::lexical_topic ● Spoilers: Removed in 5.24
  • 32. London Perl Workshop 2016 $/ = $n Reads $n Characters ● Setting $/ to a reference to an integer ● (Previously) Reads that number of bytes ● (Now) Reads that number of characters ● This is almost certainly what you want ● Unicode complicates everything
  • 33. London Perl Workshop 2016 qw(...) Needs Extra Parentheses ● Correcting a parsing bug ● foreach qw(foo bar baz) { ... } ● Perl previously added the missing parentheses ● Now it doesn't ● foreach (qw(foo bar baz)) { ... }
  • 34. London Perl Workshop 2016 Unicode 6.2 ● Unicode complicates everything! ● http://www.unicode.org/versions/Unicode6.2.0 ● "Version 6.2 of the Unicode Standard is a special release dedicated to the early publication of the newly encoded Turkish lira sign."
  • 35. London Perl Workshop 2016 5.20
  • 36. London Perl Workshop 2016 5.20 ● 5.20.0 - 27 May 2014 ● 5.20.1 - 14 Sep 2014 ● 5.20.2 - 14 Feb 2015 ● 5.20.3 - 12 Sep 2015
  • 37. London Perl Workshop 2016 5.20 Features ● Subroutine signatures (experimental) ● %hash{...} and %array[...] slices ● Postfix dereferencing (experimental) ● Unicode 6.3
  • 38. London Perl Workshop 2016 Subroutine Signatures ● Subroutines can now have a signature ● sub foo ($bar, $baz) { ... } ● use feature 'signatures' ● Experimental ● no warnings experimental::signatures
  • 39. London Perl Workshop 2016 Mandatory Parameters ● sub foo ($bar, $baz) { ... } ● Checks the number of parameters ● Throws exception if the wrong number ● Assigns parameters to $bar and $baz
  • 40. London Perl Workshop 2016 Unnamed Parameter ● Parameters can be unnamed ● Use $ without a name ● sub foo ($bar, $, $baz) { ... } ● Must pass three parameters ● Second parameter is not assigned to a variable ● All parameters still in @_
  • 41. London Perl Workshop 2016 Optional Parameters ● Make parameters optional by giving them a default ● sub foo ($bar, $baz = 0) { ... } ● Call with one or two parameters ● $baz set to 0 by default
  • 42. London Perl Workshop 2016 Slurpy Parameters ● 'Slurpy' parameters follow postional parameters ● Assign them to an array ● sub foo ($bar, @baz) { ... } ● foo('a', 'b', 'c'); ● Or a hash ● sub foo ($bar, %baz) { ... } ● foo('a', 'b', 'c'); ● foo('a', b => 'c');
  • 43. London Perl Workshop 2016 %hash{...} and %array[...] Slices ● Old array slices ● @slice = @array[1, 3..5] ● Returns four elements from the array ● Also with hashes ● @slice = @hash{'foo', 'bar', 'baz'} ● Returns three values from the hash
  • 44. London Perl Workshop 2016 New Hash Slices ● New %h{...} slice syntax ● %subhash = %hash{'foo', 'bar', 'baz'} ● Returns three key/value pairs ● Also with arrays ● @slice = %array[1, 3..5] ● Returns four index/element pairs
  • 45. London Perl Workshop 2016 Postfix Dereferencing ● no warnings experimental::postderef ● New syntax for dereferencing ● Follows left-to-right rules throughout
  • 46. London Perl Workshop 2016 Postfix vs Prefix ● $sref->$*; # same as ${ $sref } ● $aref->@*; # same as @{ $aref } ● $href->%*; # same as %{ $href } ● $cref->&*; # same as &{ $cref } ● $gref->**; # same as *{ $gref }
  • 47. London Perl Workshop 2016 Left to Right Throughout ● Old style ● @arr = @{$r->{foo}[0]{bar}} ● New style ● @arr = $r->{foo}[0]{bar}->@*
  • 48. London Perl Workshop 2016 Unicode 6.3 ● Unicode complicates everything! ● http://www.unicode.org/versions/Unicode6.3.0 ● "Version 6.3 of the Unicode Standard is a special release focused on delivering significantly improved bidirectional behavior."
  • 49. London Perl Workshop 2016 5.22
  • 50. London Perl Workshop 2016 5.22 ● 5.22.0 - 01 Jun 2015 ● 5.22.1 - 13 Dec 2015 ● 5.22.2 - 29 Apr 2016
  • 51. London Perl Workshop 2016 5.22 Features ● New bitwise operators ● Double diamond operator ● New regex boundaries b{...} ● New /n option on regexes ● Unicode 7.0 ● Omitting % and & on hash and array names now an error
  • 52. London Perl Workshop 2016 5.22 Features (cont) ● defined(@array) and defined(%hash) now fatal error ● %hash->{$key} and @array->[$idx] now fatal errors ● perlunicook ● find2perl, a2p, s2p removed ● CGI removed ● Module::Build removed
  • 53. London Perl Workshop 2016 New Bitwise Operators ● Old bitwise operators ● ~, &, |, ^ ● Expect numbers as operands ● "Work" on strings too ● No numeric/string differentiation
  • 54. London Perl Workshop 2016 New Bitwise Operators ● use feature 'bitwise'; ● no warnings 'experimental::bitwise'; ● Or use experimental 'bitwise'; ● Old operators are always numeric ● New string bitwise operators ● ~., &., |., ^.
  • 55. London Perl Workshop 2016 Double Diamond Operator ● <<>> ● Like <> ● Uses three-arg open() ● All elements of @ARGV treated as filenames ● |foo will no longer work
  • 56. London Perl Workshop 2016 New Regex Boundaries ● Extensions to b ● b{wb} - Word boundary – Like b but cleverer about punctuation within words ● b{sb} - Sentence boundary ● b{gcb} - Grapheme cluster boundary – Unicode complicates everything!
  • 57. London Perl Workshop 2016 /n Option on Regexes ● New option for m/.../ and s/.../.../ ● Turns off call capturing ● /(w+)/ - fills in $1 ● /(w+)/n - doesn't ● See also (?:w+)
  • 58. London Perl Workshop 2016 Unicode 7.0 ● Unicode complicates everything! ● http://www.unicode.org/versions/Unicode7.0.0 ● "Unicode 7.0 adds a total of 2,834 characters, encompassing 23 new scripts and many new symbols, as well as character additions to many existing scripts"
  • 59. London Perl Workshop 2016 Unicode 7.0 ● Two newly adopted currency symbols: the manat, used in Azerbaijan, and the ruble, used in Russia and other countries ● Pictographic symbols (including many emoji), geometric symbols, arrows, and ornaments originating from the Wingdings and Webdings sets ● Twenty-three new lesser-used and historic scripts extending support for written languages of North America, China, India, other Asian countries, and Africa ● Letters used in Teuthonista and other transcriptional systems, and a new notational set, Duployan
  • 60. London Perl Workshop 2016 Omitting % and @ on Hash and Array Names ● You used to be able to omit sigils in some circumstances ● Very stupid thing to do ● Deprecation warning since 5.000 (1994!) ● Now a fatal error
  • 61. London Perl Workshop 2016 defined(@array) and defined(%hash) now Fatal Errors ● Another parser bug fixed ● Deprecated since 5.6.1 ● Deprecation warning since 5.16 ● Now a fatal error
  • 62. London Perl Workshop 2016 %hash->{$key} and @array- >[$idx] now Fatal Errors ● Bet you didn't know you could do that ● Now you can't ● Deprecated since "before 5.8" ● Now a fatal error
  • 63. London Perl Workshop 2016 perlunicook ● New cookbook of Unicode recipes ● By Tom Christiansen ● Well worth reading ● If you think you don't care about Unicode, you're wrong ● Unicode complicates everything
  • 64. London Perl Workshop 2016 find2perl, a2p, s2p Removed ● Old programs that converted from standard Unix utilities ● No-one had used them for years ● No-one had maintained them for years ● No-one cares they're gone
  • 65. London Perl Workshop 2016 CGI Removed ● Contentious ● CGI is a terrible way to write web applications ● Including CGI.pm with Perl was seen as an endorsement ● Best to remove it ● Use PSGI/Plack instead
  • 66. London Perl Workshop 2016 Module::Build Removed ● Written as a replacement for ExtUtils::MakeMaker ● Pure Perl ● Didn't use make ● Cross-platform ● Failed experiment
  • 67. London Perl Workshop 2016 5.24
  • 68. London Perl Workshop 2016 5.24 ● 5.24.0 - 09 May 2016
  • 69. London Perl Workshop 2016 5.24 Features ● Postfix dereferencing no longer experimental ● Unicode 8.0 ● b{lb} ● Shebang redirects to Perl6 ● autoderef removed
  • 70. London Perl Workshop 2016 Postfix Dereferecing ● Added in 5.20 ● No longer experimental
  • 71. London Perl Workshop 2016 Unicode 8.0 ● Unicode complicates everything! ● http://www.unicode.org/versions/Unicode8.0.0 ● "Unicode 8.0 adds a total of 7,716 characters, encompassing six new scripts and many new symbols, as well as character additions to several existing scripts."
  • 72. London Perl Workshop 2016 Unicode 8.0 ● A set of lowercase Cherokee syllables, forming case pairs with the existing Cherokee characters ● A large collection of CJK unified ideographs ● Emoji symbols and symbol modifiers for implementing skin tone diversity ● Georgian lari currency symbol ● Letters to support the Ik language in Uganda, Kulango in the Côte d’Ivoire, and other languages of Africa ● The Ahom script for support of the Tai Ahom language in India ● Arabic letters to support Arwi—the Tamil language written in the Arabic script
  • 73. London Perl Workshop 2016 b{lb} ● New regex boundary ● Matches a (potential) lib break ● Place where you could break a line ● Unicode property ● See also Unicode::Linebreak
  • 74. London Perl Workshop 2016 Shebang Redirects to Perl 6 ● Perl will start another program given in the shebang ● E.g. #!/usr/bin/ruby ● Only if the path doesn't contain "perl" ● Now works for "perl6" too
  • 75. London Perl Workshop 2016 Auto-deref Removed ● Added in 5.14 ● Array and hash functions work on references ● push @$arr_ref vs push $arr_ref ● keys %$hash_ref vs keys %$hash_ref ● "Deemed unsuccessful"
  • 76. London Perl Workshop 2016 5.26
  • 77. London Perl Workshop 2016 Perl 5.26 ● Released next spring ● Perl 5.25 is dev branch ● A sneak peek
  • 78. London Perl Workshop 2016 Perl 5.26 ● Lexical subroutines no longer experimental ● Unicode 9.0.0 ● Declare references to variables - my $x
  • 79. London Perl Workshop 2016 Staying Up To Date
  • 80. London Perl Workshop 2016 Staying Up To Date ● How do you know a new version of Perl has been released? ● How do you know what is in a new release of Perl?
  • 81. London Perl Workshop 2016 Keep Up To Date With Perl News ● @perlfoundation ● Reddit ● Perl Weekly
  • 82. London Perl Workshop 2016 @perlfoundation ● The Perl Foundation Twitter account ● ~7,000 followers ● Run by volunteers ● Tries to be first with Perl news
  • 83. London Perl Workshop 2016 Reddit ● Perl subreddit ● http://reddit.com/r/perl ● Links to interesting Perl articles/announcements ● Also help students with their Perl homework
  • 84. London Perl Workshop 2016 Perl Weekly ● Weekly Perl email ● Links to interesting Perl articles/announcements ● Curated by humans ● Web feed ● Highly recommended
  • 85. London Perl Workshop 2016 What Is In The New Release? ● Read the perldelta man page ● Included with every Perl release ● Older versions available too
  • 86. London Perl Workshop 2016 Conclusion
  • 87. London Perl Workshop 2016 Conclusion ● Perl has an annual release cycle ● Interesting/useful changes in each release ● Worth keeping up to date ● A reason to upgrade?
  • 88. London Perl Workshop 2016 Questions? ● Any questions? ● Coffee break
  • 89. London Perl Workshop 2016 Advert ● Magnum Solutions Ltd ● Perl Training ● Perl Development ● Code Review ● Design Review ● dave@mag-sol.com