SlideShare una empresa de Scribd logo
1 de 211
Introducing Modern Perl Dave Cross Magnum Solutions Ltd [email_address]
Modern Perl ,[object Object]
Achieved great popularity in the 1990s
“The duct tape of the internet”
Perl has moved on a lot since then
Many people's perceptions of Perl haven't
Modern Perl ,[object Object]
Surveying modern modules and techniques
A lot to cover
Only an overview
Plenty of pointers to more information
What We Will Cover ,[object Object]
Template Toolkit
DateTime
DBIx::Class
TryCatch
What We Will Cover ,[object Object]
autodie
Catalyst
PSGI/Plack
Schedule ,[object Object]
11:30 – 11:45 Coffee
13:00 – 14:00 Lunch
15:30 – 15:40 Coffee
18:00 End
18:00 Pre-Conference Meeting
Resources ,[object Object]
Modern Core Perl
Perl Releases ,[object Object]
Major release every year
Minor releases when required
Release Numbering ,[object Object]
Perl 5.10 ,[object Object]
Well worth upgrading
New Features ,[object Object]
Switch operator
Smart matching
say()
Lexical $_
New Features ,[object Object]
Stacked file tests
Regex improvements
Many more
Defined Or ,[object Object]
$val = $val || $default;
$val ||= $default;
What if 0 is a valid value?
Need to check “definedness”
$val = defined $val   ? $val : $default;
$val = $default unless defined $val;
Defined Or ,[object Object]
$val = $val // $default;
A different slant on truth
Checks definedness
Shortcircuit version too
$val //= $value;
Switch Statement ,[object Object]
Source filter
Parser limitations ,[object Object]
eval ,[object Object]
Given ... When ,[object Object]
Case is spelled “when”
Powerful matching syntax
Given Example ,[object Object]
New Keywords ,[object Object]
when
default
continue
given ,[object Object]
Assigns the result of EXPR to $_ within the following block
Similar to  do { my $_ = EXPR; ... }
when ,[object Object]
Uses smart matching to compare $_ with EXPR
Equivalent to  when ($_ ~~ EXPR)
~~ is the new smart match operator
Compares two values and “does the right thing”
default ,[object Object]
default block is optional
continue ,[object Object]
Normal behaviour is to break out of given block once the first when condition is matched
continue ,[object Object]
Smart Matching ,[object Object]
Different kinds of matches
Dependent on the types of the operands
See “perldoc perlsyn” for the full details
CAVEAT: Subject to change
Smart Match Examples ,[object Object]
@foo ~~ $bar; # array contains value
%foo ~~ $bar; # hash key exists
$foo ~~ qr{$bar}; # regex match
@foo ~~ @bar; # arrays are identical
%foo ~~ %bar; # hash keys match
Many more alternatives
say() ,[object Object]
Adds a new line at the end of each call
say($foo); # print $foo, “”;
Two characters shorter than print
Less typing
Lexical $_ ,[object Object]
Always exists in main package
Can lead to subtle bugs when not localised correctly
Can now use  my $_  to create a lexically scoped variable called $_
State Variables ,[object Object]
sub variables {   my $x;   say ++$x; } variables() for 1 .. 3;
State Variables ,[object Object]
sub variables {   state $x;   say ++$x; } variables() for 1 .. 3;
Like static variables in C
Stacked File Tests ,[object Object]
-f -w -x $file
Previously you couldn't
Now you can
Equivalent to
-x $file && -w _ && -f _
Regex Improvements ,[object Object]
Named capture buffers
Possessive quantifiers
Relative backreferences
New escape sequences
Many more
Named Capture Buffers ,[object Object]
Named captures retain their names
(?<name> ... ) to define
Use new %+ hash to access them
Named Capture Example ,[object Object]
Possessive Quantifiers ,[object Object]
Grab as much as they can
Never give it back
Finer control over backtracking
'aaaa' =~ /a++a/
Never matches
Relative Backreferences ,[object Object]
More powerful version of   ,   , etc
{1}  is the same as
{-1}  is the last capture buffer
{-2}  is the one before that
New Escape Sequences ,[object Object]
  – Vertical white space
Also    and
Accessing New Features ,[object Object]
They are therefore turned off by default
Turn them on with the  feature  pragma
use feature 'say';
use feature 'switch';
use feature 'state';
use feature ':5.10';
Implicit Loading ,[object Object]
Require a high enough version of Perl
use 5.10.0; # Or higher
-E command line option
perl -e 'say “hello”'
perl -E 'say “hello”'
Perl 5.12 ,[object Object]
5.12 Enhancements ,[object Object]
New modules ,[object Object]
parent
5.12 Enhancements ,[object Object]
... operator
Implicit strictures
Y2038 compliance
... Operator ,[object Object]
Used to stand in for unwritten code
sub unimplemented {   ... }
Code compiles
Throws an “unimplemented” exception when run
package NAME VER ,[object Object]
package My::Package 1.23;
Equivalent to
package My::Package; our $VERSION = 1.23;
Implicit Strictures ,[object Object]
use 5.12.0;
Is equivalent to
use strict; use feature ':5.12';
Y2038 Compliance ,[object Object]
Smart Match Changes ,[object Object]
No longer commutative
See new table in perlsyn
CAVEAT: More changes coming
New Modules ,[object Object]
autodie
parent ,[object Object]
Perl 5.14 ,[object Object]
5.16 due spring 2012
5.14 Enhancements ,[object Object]
Container functions accept references
Package block
New modules
Non-destructive substitution ,[object Object]
Copies input
Acts on copy
Original unmodifed
$_ = 'cat'; $new = s/cat/dog/r'; # $_ remains 'cat'
Container functions accept references ,[object Object]
@keys = keys %hash ,[object Object],[object Object]
@keys = keys %$hashref
Container functions accept references ,[object Object]
@keys = keys $hash_ref ,[object Object]
Package block ,[object Object]
package MyPackage { ... }
Equivalent to
{ package MyPackage; ... }
Can also declare a version
package MyPackage 1.23 { ... }
New Modules ,[object Object]
CPAN::Meta::YAML & JSON::PP
CPAN::Meta
CPAN::Meta::Spec & CPAN::Meta::History
Module::Metadata
New Modules ,[object Object]
CPAN::Meta::YAML & JSON::PP
CPAN::Meta
CPAN::Meta::Spec & CPAN::Meta::History

Más contenido relacionado

La actualidad más candente

perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe Jiang
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
Dave Cross
 
PHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsPHP Underground Session 1: The Basics
PHP Underground Session 1: The Basics
Robin Hawkes
 

La actualidad más candente (20)

Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Php Basic
Php BasicPhp Basic
Php Basic
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Perl
PerlPerl
Perl
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
PHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsPHP Underground Session 1: The Basics
PHP Underground Session 1: The Basics
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Perl
PerlPerl
Perl
 

Similar a Introduction to Modern Perl

course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 

Similar a Introduction to Modern Perl (20)

What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
PHP
PHP PHP
PHP
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Php
PhpPhp
Php
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Cleancode
CleancodeCleancode
Cleancode
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Php essentials
Php essentialsPhp essentials
Php essentials
 

Más de Dave Cross

Object-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and MooseObject-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and Moose
Dave Cross
 

Más de Dave Cross (20)

Measuring the Quality of Your Perl Code
Measuring the Quality of Your Perl CodeMeasuring the Quality of Your Perl Code
Measuring the Quality of Your Perl Code
 
Apollo 11 at 50 - A Simple Twitter Bot
Apollo 11 at 50 - A Simple Twitter BotApollo 11 at 50 - A Simple Twitter Bot
Apollo 11 at 50 - A Simple Twitter Bot
 
Monoliths, Balls of Mud and Silver Bullets
Monoliths, Balls of Mud and Silver BulletsMonoliths, Balls of Mud and Silver Bullets
Monoliths, Balls of Mud and Silver Bullets
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
I'm A Republic (Honest!)
I'm A Republic (Honest!)I'm A Republic (Honest!)
I'm A Republic (Honest!)
 
Web Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your GooglejuiceWeb Site Tune-Up - Improve Your Googlejuice
Web Site Tune-Up - Improve Your Googlejuice
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Freeing Tower Bridge
Freeing Tower BridgeFreeing Tower Bridge
Freeing Tower Bridge
 
Modern Perl Catch-Up
Modern Perl Catch-UpModern Perl Catch-Up
Modern Perl Catch-Up
 
Error(s) Free Programming
Error(s) Free ProgrammingError(s) Free Programming
Error(s) Free Programming
 
Medium Perl
Medium PerlMedium Perl
Medium Perl
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
 
Conference Driven Publishing
Conference Driven PublishingConference Driven Publishing
Conference Driven Publishing
 
Conference Driven Publishing
Conference Driven PublishingConference Driven Publishing
Conference Driven Publishing
 
TwittElection
TwittElectionTwittElection
TwittElection
 
Perl in the Internet of Things
Perl in the Internet of ThingsPerl in the Internet of Things
Perl in the Internet of Things
 
Return to the Kingdom of the Blind
Return to the Kingdom of the BlindReturn to the Kingdom of the Blind
Return to the Kingdom of the Blind
 
Github, Travis-CI and Perl
Github, Travis-CI and PerlGithub, Travis-CI and Perl
Github, Travis-CI and Perl
 
Object-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and MooseObject-Oriented Programming with Perl and Moose
Object-Oriented Programming with Perl and Moose
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 

Introduction to Modern Perl