Enviar pesquisa
Carregar
Perl Development (Sample Courseware)
•
6 gostaram
•
1,567 visualizações
Garth Gilmour
Seguir
Tecnologia
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 176
Recomendados
Boogie 2011 Hi-Lite
Boogie 2011 Hi-Lite
AdaCore
Workin ontherailsroad
Workin ontherailsroad
Jim Jones
WorkinOnTheRailsRoad
WorkinOnTheRailsRoad
webuploader
pebble - Building apps on pebble
pebble - Building apps on pebble
Aniruddha Chakrabarti
Coding standards
Coding standards
Mark Reynolds
Coding standard
Coding standard
FAROOK Samath
Cp 111 lecture 3
Cp 111 lecture 3
HafidhyMasoud
LIL Presentation
LIL Presentation
badsectoracula
Recomendados
Boogie 2011 Hi-Lite
Boogie 2011 Hi-Lite
AdaCore
Workin ontherailsroad
Workin ontherailsroad
Jim Jones
WorkinOnTheRailsRoad
WorkinOnTheRailsRoad
webuploader
pebble - Building apps on pebble
pebble - Building apps on pebble
Aniruddha Chakrabarti
Coding standards
Coding standards
Mark Reynolds
Coding standard
Coding standard
FAROOK Samath
Cp 111 lecture 3
Cp 111 lecture 3
HafidhyMasoud
LIL Presentation
LIL Presentation
badsectoracula
Create Your Own Language
Create Your Own Language
Hamidreza Soleimani
Coding standard and coding guideline
Coding standard and coding guideline
Dhananjaysinh Jhala
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Adair Dingle
Lexing and parsing
Lexing and parsing
Elizabeth Smith
Presentation c++
Presentation c++
JosephAlex21
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
Adair Dingle
XKE - Programming Paradigms & Constructs
XKE - Programming Paradigms & Constructs
Nicolas Demengel
PL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and Scope
Schwannden Kuo
PDF Localization
PDF Localization
Suite Solutions
Fusing Modeling and Programming into Language-Oriented Programming
Fusing Modeling and Programming into Language-Oriented Programming
Markus Voelter
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
techfreak
Dost.jar and fo.jar
Dost.jar and fo.jar
Suite Solutions
Programming Paradigms
Programming Paradigms
Janeve George
Andy On Closures
Andy On Closures
melbournepatterns
6 data types
6 data types
Munawar Ahmed
Introduction to c_sharp
Introduction to c_sharp
HEM Sothon
Chapter1pp
Chapter1pp
J. C.
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Talentica Software
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Charitha Gamage
Aerohive Configuration guide.
Aerohive Configuration guide.
armaan7139
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
CODE BLUE
Mais conteúdo relacionado
Mais procurados
Create Your Own Language
Create Your Own Language
Hamidreza Soleimani
Coding standard and coding guideline
Coding standard and coding guideline
Dhananjaysinh Jhala
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Adair Dingle
Lexing and parsing
Lexing and parsing
Elizabeth Smith
Presentation c++
Presentation c++
JosephAlex21
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
Adair Dingle
XKE - Programming Paradigms & Constructs
XKE - Programming Paradigms & Constructs
Nicolas Demengel
PL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and Scope
Schwannden Kuo
PDF Localization
PDF Localization
Suite Solutions
Fusing Modeling and Programming into Language-Oriented Programming
Fusing Modeling and Programming into Language-Oriented Programming
Markus Voelter
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
Schwannden Kuo
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
techfreak
Dost.jar and fo.jar
Dost.jar and fo.jar
Suite Solutions
Programming Paradigms
Programming Paradigms
Janeve George
Andy On Closures
Andy On Closures
melbournepatterns
6 data types
6 data types
Munawar Ahmed
Introduction to c_sharp
Introduction to c_sharp
HEM Sothon
Chapter1pp
Chapter1pp
J. C.
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Talentica Software
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Charitha Gamage
Mais procurados
(20)
Create Your Own Language
Create Your Own Language
Coding standard and coding guideline
Coding standard and coding guideline
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Object-oriented Design: Polymorphism via Inheritance (vs. Delegation)
Lexing and parsing
Lexing and parsing
Presentation c++
Presentation c++
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
XKE - Programming Paradigms & Constructs
XKE - Programming Paradigms & Constructs
PL Lecture 02 - Binding and Scope
PL Lecture 02 - Binding and Scope
PDF Localization
PDF Localization
Fusing Modeling and Programming into Language-Oriented Programming
Fusing Modeling and Programming into Language-Oriented Programming
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
Dost.jar and fo.jar
Dost.jar and fo.jar
Programming Paradigms
Programming Paradigms
Andy On Closures
Andy On Closures
6 data types
6 data types
Introduction to c_sharp
Introduction to c_sharp
Chapter1pp
Chapter1pp
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Destaque
Aerohive Configuration guide.
Aerohive Configuration guide.
armaan7139
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
CODE BLUE
Chapter5ccna
Chapter5ccna
ernestlithur
6421 b Module-10
6421 b Module-10
Bibekananada Jena
Chapter3ccna
Chapter3ccna
ernestlithur
ccna
ccna
Saimir Ciraku
Workshop on Cyber security
Workshop on Cyber security
Mehedi Hasan
Chapter10ccna
Chapter10ccna
ernestlithur
US Pmp Overview 2008
US Pmp Overview 2008
Jaydeep Adhikari
CSE 2016 Future of Cyber Security by Matthew Rosenquist
CSE 2016 Future of Cyber Security by Matthew Rosenquist
Matthew Rosenquist
The Future of Cyber Security
The Future of Cyber Security
Stephen Lahanas
IT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community College
Atlantic Training, LLC.
ISO 27001 - information security user awareness training presentation -part 2
ISO 27001 - information security user awareness training presentation -part 2
Tanmay Shinde
DTS Solution - Building a SOC (Security Operations Center)
DTS Solution - Building a SOC (Security Operations Center)
Shah Sheikh
Information Security Awareness Training by Wilfrid Laurier University
Information Security Awareness Training by Wilfrid Laurier University
Atlantic Training, LLC.
Security Awareness Training by Fortinet
Security Awareness Training by Fortinet
Atlantic Training, LLC.
Building a Next-Generation Security Operation Center Based on IBM QRadar and ...
Building a Next-Generation Security Operation Center Based on IBM QRadar and ...
IBM Security
ISO 27001 - information security user awareness training presentation - Part 1
ISO 27001 - information security user awareness training presentation - Part 1
Tanmay Shinde
Cyber Security 101: Training, awareness, strategies for small to medium sized...
Cyber Security 101: Training, awareness, strategies for small to medium sized...
Stephen Cobb
SOC presentation- Building a Security Operations Center
SOC presentation- Building a Security Operations Center
Michael Nickle
Destaque
(20)
Aerohive Configuration guide.
Aerohive Configuration guide.
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
CODE BLUE 2014 : Physical [In]Security: It’s not ALL about Cyber by Inbar Raz
Chapter5ccna
Chapter5ccna
6421 b Module-10
6421 b Module-10
Chapter3ccna
Chapter3ccna
ccna
ccna
Workshop on Cyber security
Workshop on Cyber security
Chapter10ccna
Chapter10ccna
US Pmp Overview 2008
US Pmp Overview 2008
CSE 2016 Future of Cyber Security by Matthew Rosenquist
CSE 2016 Future of Cyber Security by Matthew Rosenquist
The Future of Cyber Security
The Future of Cyber Security
IT Security Awarenesss by Northern Virginia Community College
IT Security Awarenesss by Northern Virginia Community College
ISO 27001 - information security user awareness training presentation -part 2
ISO 27001 - information security user awareness training presentation -part 2
DTS Solution - Building a SOC (Security Operations Center)
DTS Solution - Building a SOC (Security Operations Center)
Information Security Awareness Training by Wilfrid Laurier University
Information Security Awareness Training by Wilfrid Laurier University
Security Awareness Training by Fortinet
Security Awareness Training by Fortinet
Building a Next-Generation Security Operation Center Based on IBM QRadar and ...
Building a Next-Generation Security Operation Center Based on IBM QRadar and ...
ISO 27001 - information security user awareness training presentation - Part 1
ISO 27001 - information security user awareness training presentation - Part 1
Cyber Security 101: Training, awareness, strategies for small to medium sized...
Cyber Security 101: Training, awareness, strategies for small to medium sized...
SOC presentation- Building a Security Operations Center
SOC presentation- Building a Security Operations Center
Semelhante a Perl Development (Sample Courseware)
Perl Reference.ppt
Perl Reference.ppt
AshleshaKulkarni4
Introduction to writing readable and maintainable Perl
Introduction to writing readable and maintainable Perl
Alex Balhatchet
Perl_Part1
Perl_Part1
Frank Booth
Pearl
Pearl
Naga Dinesh
perl lauange
perl lauange
Naga Dinesh
Introduction to Modern Perl
Introduction to Modern Perl
Dave Cross
Dart programming language
Dart programming language
Aniruddha Chakrabarti
Cs3430 lecture 15
Cs3430 lecture 15
Tanwir Zaman
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
mayilcebrayilov15
Introduction To Perl - SpringPeople
Introduction To Perl - SpringPeople
SpringPeople
Coding standards for java
Coding standards for java
maheshm1206
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Alex Balhatchet
Perl_Part5
Perl_Part5
Frank Booth
topic_perlcgi
topic_perlcgi
tutorialsruby
topic_perlcgi
topic_perlcgi
tutorialsruby
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
ActiveState
Perl programming tsp
Perl programming tsp
Pradeep Kumar TS
Perl
Perl
Ahmed Hmed
python and perl
python and perl
Mara Angelica Refraccion
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
eSparkBiz
Semelhante a Perl Development (Sample Courseware)
(20)
Perl Reference.ppt
Perl Reference.ppt
Introduction to writing readable and maintainable Perl
Introduction to writing readable and maintainable Perl
Perl_Part1
Perl_Part1
Pearl
Pearl
perl lauange
perl lauange
Introduction to Modern Perl
Introduction to Modern Perl
Dart programming language
Dart programming language
Cs3430 lecture 15
Cs3430 lecture 15
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
Introduction To Perl - SpringPeople
Introduction To Perl - SpringPeople
Coding standards for java
Coding standards for java
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Perl_Part5
Perl_Part5
topic_perlcgi
topic_perlcgi
topic_perlcgi
topic_perlcgi
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Perl programming tsp
Perl programming tsp
Perl
Perl
python and perl
python and perl
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
Mais de Garth Gilmour
Compose in Theory
Compose in Theory
Garth Gilmour
Kotlin / Android Update
Kotlin / Android Update
Garth Gilmour
TypeScript Vs. KotlinJS
TypeScript Vs. KotlinJS
Garth Gilmour
Shut Up And Eat Your Veg
Shut Up And Eat Your Veg
Garth Gilmour
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS Adventures
Garth Gilmour
The Heat Death Of Enterprise IT
The Heat Death Of Enterprise IT
Garth Gilmour
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
Type Driven Development with TypeScript
Type Driven Development with TypeScript
Garth Gilmour
Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)
Garth Gilmour
Using Kotlin, to Create Kotlin,to Teach Kotlin,in Space
Using Kotlin, to Create Kotlin,to Teach Kotlin,in Space
Garth Gilmour
Is Software Engineering A Profession?
Is Software Engineering A Profession?
Garth Gilmour
Social Distancing is not Behaving Distantly
Social Distancing is not Behaving Distantly
Garth Gilmour
The Great Scala Makeover
The Great Scala Makeover
Garth Gilmour
Transitioning Android Teams Into Kotlin
Transitioning Android Teams Into Kotlin
Garth Gilmour
Simpler and Safer Java Types (via the Vavr and Lambda Libraries)
Simpler and Safer Java Types (via the Vavr and Lambda Libraries)
Garth Gilmour
The Three Horse Race
The Three Horse Race
Garth Gilmour
The Bestiary of Pure Functional Programming
The Bestiary of Pure Functional Programming
Garth Gilmour
BelTech 2019 Presenters Workshop
BelTech 2019 Presenters Workshop
Garth Gilmour
Kotlin The Whole Damn Family
Kotlin The Whole Damn Family
Garth Gilmour
Mais de Garth Gilmour
(20)
Compose in Theory
Compose in Theory
Kotlin / Android Update
Kotlin / Android Update
TypeScript Vs. KotlinJS
TypeScript Vs. KotlinJS
Shut Up And Eat Your Veg
Shut Up And Eat Your Veg
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS Adventures
The Heat Death Of Enterprise IT
The Heat Death Of Enterprise IT
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Type Driven Development with TypeScript
Type Driven Development with TypeScript
Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)
Using Kotlin, to Create Kotlin,to Teach Kotlin,in Space
Using Kotlin, to Create Kotlin,to Teach Kotlin,in Space
Is Software Engineering A Profession?
Is Software Engineering A Profession?
Social Distancing is not Behaving Distantly
Social Distancing is not Behaving Distantly
The Great Scala Makeover
The Great Scala Makeover
Transitioning Android Teams Into Kotlin
Transitioning Android Teams Into Kotlin
Simpler and Safer Java Types (via the Vavr and Lambda Libraries)
Simpler and Safer Java Types (via the Vavr and Lambda Libraries)
The Three Horse Race
The Three Horse Race
The Bestiary of Pure Functional Programming
The Bestiary of Pure Functional Programming
BelTech 2019 Presenters Workshop
BelTech 2019 Presenters Workshop
Kotlin The Whole Damn Family
Kotlin The Whole Damn Family
Último
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Zilliz
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Jeffrey Haguewood
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
Kumar Satyam
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Zilliz
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Dropbox
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, Adobe
apidays
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
AnitaRaj43
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
apidays
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Rustici Software
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
apidays
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
MadyBayot
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2
Architecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Último
(20)
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
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, Adobe
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
Architecting Cloud Native Applications
Architecting Cloud Native Applications
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Perl Development (Sample Courseware)
1.
Perl Development Sample
Courseware Created October 2008 © Garth Gilmour 2008
2.
3.
Introduction to Perl
History and Basic Concepts © Garth Gilmour 2008
4.
5.
6.
Comparing Perl, Python
and Ruby © Garth Gilmour 2008 Perl Python Ruby Documentation ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Library Support ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ OO Support ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Power ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Approachability ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Ease of Mastery ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ C / C++ Interop ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Java / .NET Interop ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ Web Frameworks ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦
7.
8.
© Garth Gilmour
2008 Scripts Core language features Programs Strict module Subroutines References Applications Best Practises Named Parameters Modules and classes
9.
10.
11.
12.
13.
14.
© Garth Gilmour
2008 Symbol Table Typeglob $fred = 12; @fred = (12,13,14); %fred = (k1 =>12, k2 => 14); sub fred { return 101; } Name Link fred Others… Type Link $ @ % &
15.
16.
Using Heredoc Comments
© Garth Gilmour 2008 $myvar = << "THE_END"; More than prince of cats, I can tell you. O, he is the courageous captain of compliments. He fights as you sing prick-song, keeps time, distance, and proportion; rests me his minim rest, one, two, and the third in your bosom: the very butcher of a silk button, a duellist, a duellist; a gentleman of the very first house, of the first and second cause: ah, the immortal passado! the punto reverso! the hay! THE_END print "--- START DATA ---", $myvar, "--- END DATA ---";
17.
18.
19.
Basic Programming The
Core Perl Syntax © Garth Gilmour 2008
20.
21.
22.
Operators Commonly Used
in Perl © Garth Gilmour 2008 Description Number Version String Version Addition $var1 + $var2 $var1 . $var2 Equality $var1 == $var2 $var1 eq $va2 Ordered Comparison >, <, <=, >= lt, gt, le, ge Power Of $var1 ** 3 $var1 x 3 Bitwise Comparison &, |, ^ (NB work differently for numbers and strings) Logical &&, ||, ! and, or, not (Lower precedence) Conditional $var1 = $var2 ? 12 : 14; Range 1..4 ‘ D’ .. ‘Z’
23.
© Garth Gilmour
2008 $num1 = 42; $num2 = "42"; $result = $num1 + $num2; print "adding numbers gives $result", ""x2; $result = $num1 . $num2; print "adding strings gives $result", ""x2; $result = $num2 ** 3; print "42 to the power of 3 is $result", ""x2; $result = $num1 x 3; print "42 concatenated with itself three times is $result", ""x2; if($num1 == $num2) { print '$num1 and $num2 are equal as numbers',""x2; } if($num1 eq $num2) { print '$num1 and $num2 are equal as strings',""x2; }
24.
25.
© Garth Gilmour
2008 $var1 = "abc"; $var2 = 123; $var3 = ["ab","cd","ef"]; print 'Values are $var1, $var2 and $var3 '; print "Values are $var1, $var2 and $var3 "; $path = `set path`; print "Value of path environment variable is: $path"; Values are $var1, $var2 and $var3 Values are abc, 123 and ARRAY(0x225e28) Value of path environment variable is: PATH=c:dk1.5.0_05in;C:erlitein;C:erlin;c:ubyin;C:INDOWSystem32;C:INDOWS;C:INDOWSystem32bem;
26.
27.
© Garth Gilmour
2008 $var1 = "0"; # The string "0" counts as false $var2 = ""; # The empty string also counts as false $var3 = "AB"; # Other string values are true $var4 = -12; # Other numerical values are true $var5; # Undefined values are false $var6 = undef(); # Values set to undef are false printTruth('$var1',$var1); printTruth('$var2',$var2); printTruth('$var3',$var3); printTruth('$var4',$var4); printTruth('$var5',$var5); printTruth('$var6',$var6); undef($var4); # Release storage space for var1 so it becomes undefined printTruth('$var4',$var4); sub printTruth { my ($varName,$varValue) = @_; if($varValue) { print "$varName is true"; } else { print "$varName is false"; } }
28.
29.
Special Scalar Variables
© Garth Gilmour 2008 print "This is verson $] of Perl"; print "Running on the $^O operating system"; print "The current script is $0 "; @myarray = ("ab","cd","ef","gh"); print "Elements are:"; foreach(@myarray) { print " $_ "; } This is verson 5.008008 of Perl Running on the MSWin32 operating system The current script is C:erlpecialScalars.pl Elements are: ab cd ef gh
30.
31.
© Garth Gilmour
2008 open(INPUT,"MuchAdoAboutNothing.txt"); $count = 1; foreach(<INPUT>) { print("$count: $_"); $count++; } 1: Much Ado About Nothing 2: A comedy by William Shakespear 3: 4: Act 1, Scene 1 5: Before LEONATO'S house. 6: Enter LEONATO, HERO, and BEATRICE, with a Messenger 7: 8: LEONATO 9: I learn in this letter that Don Peter of Arragon 10: comes this night to Messina.
32.
33.
© Garth Gilmour
2008 print "Enter a number"; $number = <STDIN>; chomp($number); if($number < 10) { print "$number is less than 10"; } elsif($number < 20) { print "$number is less than 20"; } elsif($number < 30) { print "$number is less than 30"; } else { print "$number is greater than 30"; } unless($number % 2 == 0) { print "$number is odd"; } Enter a number 17 17 is less than 20 17 is odd
34.
35.
© Garth Gilmour
2008 print "Enter a positive number"; $max = <STDIN>; chomp($max); if($max <= 0) { die("Number must be positive!"); } print "Demo of while loop"; print "Numbers from 0 to $max are:"; $count = 0; while($count <= $max) { print "$count"; $count++; } print "Demo of do..while loop"; print "Numbers from 0 to $max are:"; $count = 0; do { print "$count"; $count++; } while($count <= $max); print "Demo of until loop"; print "Numbers from 0 to $max are:"; $count = 0; until($count > $max) { print "$count"; $count++; } print "Demo of do..until loop"; print "Numbers from 0 to $max are:"; $count = 0; do { print "$count"; $count++; }until($count > $max); print "Demo of for loop v1"; print "Numbers from 0 to $max are:"; for($count=0; $count<= $max; $count++) { print "$count"; } print "Demo of for each loop v3"; print "Numbers from 0 to $max are:"; for(0..$max) { print "$_"; }
36.
37.
Basic Perl I/O
Using the Console and Files © Garth Gilmour 2008
38.
39.
40.
41.
42.
© Garth Gilmour
2008 open(INPUT,"input.txt"); open(OUTPUT,">output.txt"); $count = 0; while($line = <INPUT>) { print OUTPUT ++$count, "", $line; } print "Processed $count lines" This short interval was sufficient to determine d'Artagnan on the part he was to take. It was one of those events which decide the life of a man; it was a choice between the king and the cardinal--the choice made, it must be persisted in. To fight, that was to disobey the law, that was to risk his head, that was to make at one blow an enemy of a minister more powerful than the king himself. All this young man perceived, and yet, to his praise we speak it, he did not hesitate a second. Turning towards Athos and his friends, "Gentlemen," said he, "allow me to correct your words, if you please. You said you were but three, but it appears to me we are four." 1 This short interval was sufficient to determine d'Artagnan on the 2 part he was to take. It was one of those events which decide the 3 life of a man; it was a choice between the king and the 4 cardinal--the choice made, it must be persisted in. To fight, 5 that was to disobey the law, that was to risk his head, that was 6 to make at one blow an enemy of a minister more powerful than the 7 king himself. All this young man perceived, and yet, to his 8 praise we speak it, he did not hesitate a second. Turning 9 towards Athos and his friends, "Gentlemen," said he, "allow me to 10 correct your words, if you please. You said you were but three, 11 but it appears to me we are four."
43.
© Garth Gilmour
2008 open(INPUT, '<', "input.txt"); open(OUTPUT, '>', "output.txt"); $count = 0; while($line = <INPUT>) { print OUTPUT ++$count, "", $line; } print "Processed $count lines" This short interval was sufficient to determine d'Artagnan on the part he was to take. It was one of those events which decide the life of a man; it was a choice between the king and the cardinal--the choice made, it must be persisted in. To fight, that was to disobey the law, that was to risk his head, that was to make at one blow an enemy of a minister more powerful than the king himself. All this young man perceived, and yet, to his praise we speak it, he did not hesitate a second. Turning towards Athos and his friends, "Gentlemen," said he, "allow me to correct your words, if you please. You said you were but three, but it appears to me we are four." 1 This short interval was sufficient to determine d'Artagnan on the 2 part he was to take. It was one of those events which decide the 3 life of a man; it was a choice between the king and the 4 cardinal--the choice made, it must be persisted in. To fight, 5 that was to disobey the law, that was to risk his head, that was 6 to make at one blow an enemy of a minister more powerful than the 7 king himself. All this young man perceived, and yet, to his 8 praise we speak it, he did not hesitate a second. Turning 9 towards Athos and his friends, "Gentlemen," said he, "allow me to 10 correct your words, if you please. You said you were but three, 11 but it appears to me we are four."
44.
© Garth Gilmour
2008 open($input, '<', "input.txt"); open($output, '>', "output.txt"); $count = 0; while($line = <$input>) { print $output ++$count, "", $line; } print "Processed $count lines" This short interval was sufficient to determine d'Artagnan on the part he was to take. It was one of those events which decide the life of a man; it was a choice between the king and the cardinal--the choice made, it must be persisted in. To fight, that was to disobey the law, that was to risk his head, that was to make at one blow an enemy of a minister more powerful than the king himself. All this young man perceived, and yet, to his praise we speak it, he did not hesitate a second. Turning towards Athos and his friends, "Gentlemen," said he, "allow me to correct your words, if you please. You said you were but three, but it appears to me we are four." 1 This short interval was sufficient to determine d'Artagnan on the 2 part he was to take. It was one of those events which decide the 3 life of a man; it was a choice between the king and the 4 cardinal--the choice made, it must be persisted in. To fight, 5 that was to disobey the law, that was to risk his head, that was 6 to make at one blow an enemy of a minister more powerful than the 7 king himself. All this young man perceived, and yet, to his 8 praise we speak it, he did not hesitate a second. Turning 9 towards Athos and his friends, "Gentlemen," said he, "allow me to 10 correct your words, if you please. You said you were but three, 11 but it appears to me we are four."
45.
46.
© Garth Gilmour
2008 open($input, '<', "input.txt") or die "Can't open input"; open($output, '>', "output.txt") or die "Can't open output"; $count = 0; while($line = <$input>) { print($output ++$count, "", $line) or die "Can't write to file"; } print "Processed $count lines"; close($input) or die "Can't close input"; close($output) or die "Can't close output";
47.
48.
© Garth Gilmour
2008 @exampleDirectories = glob('..'); print "Perl example files are: "; foreach $dir (@exampleDirectories) { @perlFiles = glob($dir . '.pl'); foreach(@perlFiles) { #characters preceding a slash preceding # letters ending in '.pl' m/.*(+pl)/; print "$1 in $dir "; } } Perl example files are: arrayFunctions.pl in ..rrays arraysAndLists.pl in ..rrays days.pl in ..rrays forEach.pl in ..rrays fork.pl in ..oncurrency threads.pl in ..oncurrency customerDB.pl in ..atabases arraysOfArrays.pl in ..ataStructures checkingErrors.pl in ..iles indirectHandles.pl in ..iles basicHashes.pl in ..ashes extraSyntax.pl in ..ashes
49.
Arrays in Perl
Creating and Using Lists © Garth Gilmour 2008
50.
51.
© Garth Gilmour
2008 $myarray[8] = "string in 9th box"; $myarray[10] = "string in 11th box"; $count = 0; foreach(@myarray) { print $count++,": $_"; } 0: 1: 2: 3: 4: 5: 6: 7: 8: string in 9th box 9: 10: string in 11th box
52.
53.
54.
© Garth Gilmour
2008 @tstArray = qw(abc def ghi jkl mno pqr); ($first) = @tstArray; ($a,$b,$c) = @tstArray; print "First element is: $first"; print "First three elements are: $a $b $c" First element is: abc First three elements are: abc def ghi
55.
56.
57.
© Garth Gilmour
2008 @workDays = ("Monday","Tuesday","Wednesday","Thursday","Friday"); @weekendDays = qw(Saturday Sunday); @days = (@workDays,@weekendDays); $numDays = @days; $firstDay = $days[0]; $lastDay = $days[$#days]; print "There are $numDays days in a week"; print "$firstDay is the first day and $lastDay is the last day "; print "The other days are:"; foreach $day (@days) { unless($day eq $firstDay or $day eq $lastDay) { print $day, ""; } } print "The last four days are:"; @lastDays = @days[3..6]; foreach $day (@lastDays) { print $day, ""; }
58.
59.
60.
© Garth Gilmour
2008 @myarray1 = qw(abc def ghi); $val1 = pop(@myarray1); print "Just popped $val1, contents now:"; foreach(@myarray1) { print "$_"; } push(@myarray1,"zzz"); print "Just pushed zzz, contents now:"; foreach(@myarray1) { print "$_"; } $val1 = shift(@myarray1); print "Just shifted $val1, contents now:"; foreach(@myarray1) { print "$_"; } unshift(@myarray1,"AAA"); print "Just unshifted AAA, contents now:"; foreach(@myarray1) { print "$_"; } Just popped ghi, contents now: abc def Just pushed zzz, contents now: abc def zzz Just shifted abc, contents now: def zzz Just unshifted AAA, contents now: AAA def zzz
61.
Hashes in Perl
Creating and Using Tables © Garth Gilmour 2008
62.
63.
© Garth Gilmour
2008 $myhash{'k1'} = "abc"; $myhash{'k2'} = 123; $myhash{'k3'} = "def"; $myhash{'k4'} = 456; foreach $key (keys %myhash) { print $key, " indexes ", $myhash{$key}, ""; } k2 indexes 123 k1 indexes abc k3 indexes def k4 indexes 456
64.
65.
66.
67.
© Garth Gilmour
2008 %myhash = ( k1 => 123, k2 => "abc", k3 => 456, k4 => "def", k5 => 789 ); print "Keys are:"; foreach $key (keys %myhash) { print "", $key, ""; } print "Values are:"; foreach $value (values %myhash) { print "", $value, ""; } print "Entries are:"; while (($key, $value) = each(%myhash)) { print "$key indexes $value "; } Keys are: k5 k2 k1 k3 k4 Values are: 789 abc 123 456 def Entries are: k5 indexes 789 k2 indexes abc k1 indexes 123 k3 indexes 456 k4 indexes def
68.
69.
© Garth Gilmour
2008 %tstHash = ("k1","v1","k2","v2"); print "Original hash contents:"; foreach(keys(%tstHash)) { print("$_ indexes ",$tstHash{$_},""); } @tstHash {"k3","k4","k5","k6"} = (111,222,333,444); print "Hash contents after insertions:"; foreach(keys(%tstHash)) { print("$_ indexes ",$tstHash{$_},""); } ($var1,$var2,$var3) = @tstHash {"k1","k2","k3"}; print "Values in scalars are $var1 $var2 and $var3"; @elements = %tstHash; print "Array contents:"; foreach(@elements) { print "$_ "; } Original hash contents: k2 indexes v2 k1 indexes v1 Hash contents after insertions: k5 indexes 333 k2 indexes v2 k1 indexes v1 k6 indexes 444 k3 indexes 111 k4 indexes 222 Values in scalars are v1 v2 and 111 Array contents: k5 333 k2 v2 k1 v1 k6 444 k3 111 k4 222
70.
71.
© Garth Gilmour
2008 %results = ( dave => [54, 62, 73, 48], jane => [59, 67, 82, 70], fred => [92, 64, 59, 71] ); results dave jane fred 54 62 73 48 59 67 82 70 92 64 59 71
72.
73.
© Garth Gilmour
2008 %actors = ( "george clooney" => ["Oceans 11", "The Peacemaker", "O Brother Where Art Thou"], "harrison ford" => ["Star Wars","Sabrina","Indiana Jones"], "robin williams" => ["Good Morning Vietnam","Hook","The Birdcage"] ); print "The list of actors and their movies is: "; foreach $actor (keys %actors) { print "$actor starred in: "; foreach $film(@{$actors{$actor}}) { print "$film"; } } The list of actors and their movies is: robin williams starred in: Good Morning Vietnam Hook The Birdcage harrison ford starred in: Star Wars Sabrina Indiana Jones george clooney starred in: Oceans 11 The Peacemaker O Brother Where Art Thou
74.
Regular Expressions Part
1: Core Concepts © Garth Gilmour 2008
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
© Garth Gilmour
2008 ABCdefGHIjklMNOpqrSTU [A-Z]{2} Matches: AB GH MN ST ABCdefGHIjklMNOpqrSTU [A-Z]{3} Matches: ABC GHI MNO STU ABCdefGHIjklMNOpqrSTU [A-Z]{3}[a-z] Matches: ABCd GHIj MNOp
85.
© Garth Gilmour
2008 ABCdefGHIjklMNOpqrSTU [A-Z]+[a-z]+ Matches: ABCdef GHIjkl MNOpqr ABCdefGHIjklMNOpqrSTU ([A-Z]+)([a-z]+) Matches: ABCdef Group 1: ABC Group 2: def GHIjkl Group 1: GHI Group 2: jkl MNOpqr Group 1: MNO Group 2: pqr ABCdefGHIjklMNOpqrSTU [A-Za-z]+ Matches: ABCdefGHIjklMNOpqrSTU
86.
© Garth Gilmour
2008 ABCdefGHIjklMNOpqrSTU [A-Za-z]{5} Matches: ABCde fGHIj klMNO pqrST ABCdefGHIjklMNOpqrSTU ^[A-Za-z]{5} Matches: ABCde ABCdefGHIjklMNOpqrSTU [A-Za-z]{5}$ Matches: qrSTU ABCdefGHIjklMNOpqrSTU [A-Za-z]{5,8} Matches: ABCdefGH IjklMNOp rqSTU
87.
88.
Regular Expressions Part
2: Perl Syntax © Garth Gilmour 2008
89.
90.
© Garth Gilmour
2008 $data = "ABCdefGHIjklMNOpqrSTUvwxYZA"; $m1 = $data =~ m/[A-Z]/; if($m1) { print "Match one is $&"; } $m2 = $data =~ m/[A-Z]{2}/; if($m2) { print "Match two is $&"; } $m3 = $data =~ m/[A-Z]+/; if($m3) { print "Match three is $&"; } $m4 = $data =~ m/[^e]+/; if($m4) { print "Match four is $&"; } $m5 = $data =~ m/[A-Z]{3}[a-z]{2}/; if($m5) { print "Match five is $&"; } Match one is A Match two is AB Match three is ABC Match four is ABCd Match five is ABCde
91.
© Garth Gilmour
2008 $m6 = $data =~ m/[A-Z]+[a-z]+/; if($m6) { print "Match six is $&"; } $m7 = $data =~ m/[A-Za-z]{9}/; if($m7) { print "Match seven is $&"; } $m8 = $data =~ m/.+/; if($m8) { print "Match eight is $&"; } $m9 = $data =~ m/^.{8}/; if($m9) { print "Match nine is $&"; } $m10 = $data =~ m/.{8}$/; if($m10) { print "Match ten is $&"; } Match six is ABCdef Match seven is ABCdefGHI Match eight is ABCdefGHIjklMNOpqrSTUvwxYZA Match nine is ABCdefGH Match ten is TUvwxYZA
92.
© Garth Gilmour
2008 @groupOne = $data =~ m/[A-Z]{3}/g; print "First group of matches are:"; foreach(@groupOne) { print "$_"; } @groupTwo = $data =~ m/[a-z]{3}/g; print "Second group of matches are:"; foreach(@groupTwo) { print "$_"; } @groupThree = $data =~ m/.{4}/g; print "Third group of matches are:"; foreach(@groupThree) { print "$_"; } First group of matches are: ABC GHI MNO STU YZA Second group of matches are: def jkl pqr vwx Third group of matches are: ABCd efGH Ijkl MNOp qrST Uvwx
93.
94.
95.
Using Regular Expressions
in Perl © Garth Gilmour 2008 print "Enter the email address:"; chomp($email = <STDIN>); #easier to read version of ([a-z]+([a-z]+)?)megacorp(com|ie|couk) $m = $email =~ m{^ #start of string ( #start of inner match 1 [a-z]+ #one or more lowercase letters ([a-z]+)? #optionally a dot and letters (inner match 2) ) #end of inner match 1 megacorp #company name NB need to escape array (com|ie|couk) #possible domain names $ #end of string }x; if($m) { print "Recognized email for $1 in domain $3"; } else { print "Invalid address!"; }
96.
97.
© Garth Gilmour
2008 $test = "aabbccddyzeeffgghhiijjkkllmmnnoo"; # Replace all occurances of ff with FF $test =~ s/ff/FF/g; print $test , ""; # Replace any occurance of four characters at the start of the string with XX $test =~ s/^.{4}/XX/g; print $test , ""; # Replace any lower case characters with their upper case equivalents $test =~ s/([a-z])/uc($1)/eg; print $test , ""; aabbccddyzeeFFgghhiijjkkllmmnnoo XXccddyzeeFFgghhiijjkkllmmnnoo XXCCDDYZEEFFGGHHIIJJKKLLMMNNOO
98.
Regular Expressions Part
3: Advanced Concepts © Garth Gilmour 2008
99.
100.
101.
© Garth Gilmour
2008 abcDEfghIJklm [a-zA-Z]+[A-Z]{2} abcDEfghIJ Matches: abcDE fghIJ [a-zA-Z]+?[A-Z]{2} [a-zA-Z]*[A-Z]{2} abcDEfghIJklm Matches: ab cDEfg hIJkl [a-zA-Z]*?[A-Z]{2}
102.
103.
104.
105.
106.
107.
108.
Sample Unicode Properties
© Garth Gilmour 2008 Unicode Property Description AHex True for ASCII characters used in hexadecimal numbers Alpha True if a character can be compared to others ea The East Asian width of a character (full, half or narrow) IDC Indicates if a character can only be used as the first in an identifier Math True if the character is used in describing mathematical expressions Lower Indicates if a character is a lowercase letter STerm Indicates if a character is used to terminate a sentence Term Indicates if a character is punctuation that terminates a unit WSpace Indicates if a character should be treated as whitespace during parsing
109.
110.
Perl Subroutines Creating
and Calling Functions © Garth Gilmour 2008
111.
112.
© Garth Gilmour
2008 sub func { my($param1, $param2, $param3, $param4, $param5) = @_; print "func called with:"; print "$param1"; print "$param2"; print "$param3"; print "$param4"; print "$param5"; } func("abc",123,"def",456,"ghi"); func called with: abc 123 def 456 ghi
113.
114.
115.
© Garth Gilmour
2008 $var1 = "ABC"; $var2 = "DEF"; $var3 = "GHI"; print "At start $var1, $var2 and $var3"; func1(); print "At end $var1, $var2 and $var3"; sub func1 { my $var1 = "JKL"; local $var2 = "MNO"; our $var3; print "In func1 $var1, $var2 and $var3"; func2(); } sub func2 { print "In func2 $var1, $var2 and $var3"; } At start ABC, DEF and GHI In func1 JKL, MNO and GHI In func2 ABC, MNO and GHI At end ABC, DEF and GHI
116.
117.
© Garth Gilmour
2008 sub func { my %params = @_; print "Parameter fred has value $params{'fred'}"; print "Parameter wilma has value $params{'wilma'}"; print "Parameter barney has value $params{'barney'}"; } print "---------- First Call ----------"; @args1 = ("fred",20,"wilma",30,"barney",40); func(@args1); print "---------- Second Call ----------"; @args2 = (fred => 50, wilma => 60, barney => 70); func(@args2); print "---------- Third Call ----------"; func(fred => 80, wilma => 90, barney => 100); ---------- First Call ---------- Parameter fred has value 20 Parameter wilma has value 30 Parameter barney has value 40 ---------- Second Call ---------- Parameter fred has value 50 Parameter wilma has value 60 Parameter barney has value 70 ---------- Third Call ---------- Parameter fred has value 80 Parameter wilma has value 90 Parameter barney has value 100
118.
119.
Subroutines and Recursion
© Garth Gilmour 2008 sub recursion1 { until($_[0] == 0) { print "$_[0] "; $_[0]--; &recursion1; } } sub recursion2 { if(@_) { print(shift, " "); &recursion2; } } $val1 = 10; recursion1($val1); print ""; @val2 = qw(abc def ghi jkl); recursion2(@val2); 10 9 8 7 6 5 4 3 2 1 abc def ghi jkl
120.
121.
© Garth Gilmour
2008 Closures are cool! Closures are cool! Closures are cool! Closures are cool! Closures are cool! Closures are very cool! Closures are very cool! Closures are very cool! ab cd ef gh sub doTimes { for(1..$_[0]) { &{$_[1]}(); } } sub withMatches { for($_[0] =~ m/$_[1]/g) { &{$_[2]}($_); } } $ref = sub { print "Closures are cool!"; }; doTimes(5, $ref); doTimes(3, sub { print "Closures are very cool!"; }); withMatches("ab cd ef gh", "[a-z]{2}", sub { print "$_[0]"; });
122.
Error Handling Managing
Error Conditions © Garth Gilmour 2008
123.
124.
© Garth Gilmour
2008 eval { op1(); }; if($@) { print "Code threw error: ", $@; } sub op1 { op2(); } sub op2 { op3(); } sub op3 { die "BOOM!"; } eval { op1(); }; if($@) { print "Error of severity ", $@->{'severity'}; print " thrown with message ", $@->{'msg'}; } sub op1 { op2(); } sub op2 { op3(); } sub op3 { my %error = (msg => 'BOOM!', severity => 'fatal'); die error; }
125.
References in Perl
Using Memory Addresses © Garth Gilmour 2008
126.
127.
© Garth Gilmour
2008 $var1 = 124; $ref1 = var1; print $ref1, ""; print "Reference ref1 refers to value $$ref1"; print "Reference ref1 refers to value ${$ref1}"; SCALAR(0x226d98) Reference ref1 refers to value 124 Reference ref1 refers to value 124
128.
© Garth Gilmour
2008 @var2 = ("abc","def","ghi","jkl"); $ref2 = var2; print $ref2, “”; print "Reference ref2 refers to array with contents: "; foreach $val (@$ref2) { print "$val "; } print "Reference ref2 refers to array with contents: "; foreach $val (@{$ref2}) { print "$val "; } print "First three elements in array pointed to by ref2 are: "; @slice = @{$ref2}[0..2]; foreach $val (@slice) { print "$val "; } print "First item is $$ref2[0]"; print "First item is ${$ref2}[0]"; print "First item is $ref2->[0]";
129.
© Garth Gilmour
2008 ARRAY(0x226da4) Reference ref2 refers to array with contents: abc def ghi jkl Reference ref2 refers to array with contents: abc def ghi jkl First three elements in array pointed to by ref2 are: abc def ghi First item is abc First item is abc First item is abc
130.
© Garth Gilmour
2008 %var3 = ("k1","xxx","k2","yyy","k3","zzz"); $ref3 = var3; print "Reference ref3 refers to hash with contents:"; foreach $key (keys %$ref3) { print "$key indexes $$ref3{$key}"; } print "Reference ref3 refers to hash with contents:"; foreach $key (keys %{$ref3}) { print "$key indexes $ref3->{$key}"; } print "Key k1 indexes $$ref3{'k1'} "; print "Key k1 indexes ${$ref3}{'k1'} "; print "Key k1 indexes $ref3->{'k1'} ";
131.
© Garth Gilmour
2008 Reference ref3 refers to hash with contents: k2 indexes yyy k1 indexes xxx k3 indexes zzz Reference ref3 refers to hash with contents: k2 indexes yyy k1 indexes xxx k3 indexes zzz Key k1 indexes xxx Key k1 indexes xxx Key k1 indexes xxx
132.
133.
© Garth Gilmour
2008 $ref1 = ["ab","cd","ef","gh"]; $ref2 = { k1 => 123, k2 => 456, k3 => 789 }; $ref3 = sub { return $_[0] + $_[1]; }; print $ref1, ""; print $ref2, ""; print $ref3, ""; print $ref1->[0], ""; print $ref2->{'k1'}, ""; print $ref3->(12,5), ""; ARRAY(0x225f88) HASH(0x226d80) CODE(0x18303f0) ab 123 17
134.
135.
© Garth Gilmour
2008 @numerals = ( [100,"C"], [90,"XC"], [50,"L"], [40,"XL"], [10,"X"], [9,"IX"], [5,"V"], [4,"IV"], [1,"I"] ); print "Enter the number to convert to a roman numeral..."; $number = <STDIN>; chomp($number); foreach (@numerals) { my $decimal = $_->[0]; my $string = $_->[1]; my $times = int($number / $decimal); if($times > 0) { for(1..$times) { print $string; } $number = $number % $decimal; } }
136.
© Garth Gilmour
2008 $ref1 = [ ["abc","def","ghi"], ["jkl","mno","pqr"], ["stu","vwx","yza"] ]; print "Contents of 2d array are:"; foreach(@{$ref1}) { print ""; foreach(@{$_}) { print "$_ "; } print ""; } Contents of 2d array are: abc def ghi jkl mno pqr stu vwx yza
137.
© Garth Gilmour
2008 $ref = { k1 => { k4 => "ab", k5 => "cd" }, k2 => { k6 => "ef", k7 => "gh" }, k3 => { k8 => "ij", k9 => "kl" } }; print $ref->{'k1'}->{'k4'}, ""; print $ref->{'k1'}->{'k5'}, ""; print $ref->{'k2'}->{'k6'}, ""; print $ref->{'k2'}->{'k7'}, ""; print $ref->{'k3'}->{'k8'}, ""; print $ref->{'k3'}->{'k9'}, ""; ab cd ef gh ij kl
138.
Modules and Packages
Creating Reusable Code © Garth Gilmour 2008
139.
140.
141.
142.
© Garth Gilmour
2008 package Maths; require Exporter; our @ISA = ("Exporter"); @EXPORT = qw(add multiply subtract); sub add { return $_[0] + $_[1]; } sub divide { return $_[0] / $_[1]; } sub multiply { return $_[0] * $_[1]; } sub subtract { return $_[0] - $_[1]; } use Maths; print "Calculations using our maths module:"; print "40 + 30 is: ", add(40,30); print "60 - 20 is: ", subtract(60,20); print "50 * 10 is: ", multiply(50,10); # divide is not exported so it only works # if we qualify the namespace print "40 / 10 is: ", Maths::divide(40,10);
143.
© Garth Gilmour
2008 package Maths; require Exporter; our @ISA = ("Exporter"); @EXPORT_OK = qw(add multiply subtract); sub add { return $_[0] + $_[1]; } sub divide { return $_[0] / $_[1]; } sub multiply { return $_[0] * $_[1]; } sub subtract { return $_[0] - $_[1]; } use Maths qw(add multiply subtract); print "Calculations using our maths module:"; print "40 + 30 is: ", add(40,30); print "60 - 20 is: ", subtract(60,20); print "50 * 10 is: ", multiply(50,10); # divide is not exported so it only works # if we qualify the namespace print "40 / 10 is: ", Maths::divide(40,10);
144.
145.
Objects in Perl
Support for Object Oriented Programming Concepts © Garth Gilmour 2008
146.
147.
148.
© Garth Gilmour
2008 Client Code Account Objects account1 account2 withdraw { … } display { … } withdraw { … } display { … }
149.
© Garth Gilmour
2008 class Account: def __init__(self,id,balance): self.id = id self.balance = balance def withdraw(self, amount): self.balance -= amount def display(self): print "Account with id", self.id, "and balance", self.balance account1 = Account("AB12",30000) account2 = Account("CD34",45000) print "----- Before Withdrawl -----" account1.display() account2.display() account1.withdraw(250) account2.withdraw(500) print "----- After Withdrawl -----" account1.display() account2.display() ----- Before Withdrawl ----- Account with id AB12 and balance 30000 Account with id CD34 and balance 45000 ----- After Withdrawl ----- Account with id AB12 and balance 29750 Account with id CD34 and balance 44500 Constructor Class Declaration Creating Objects
150.
© Garth Gilmour
2008 class Account def initialize(id, balance) @id = id @balance = balance end def withdraw(amount) @balance -= amount end def display() puts "Account with id #{@id} and balance #{@balance}" end end account1 = Account.new("AB12",30000) account2 = Account.new("CD34",45000) puts "----- Before Withdrawl -----" account1.display() account2.display() account1.withdraw(250) account2.withdraw(500) puts "----- After Withdrawl -----" account1.display() account2.display() ----- Before Withdrawl ----- Account with id AB12 and balance 30000 Account with id CD34 and balance 45000 ----- After Withdrawl ----- Account with id AB12 and balance 29750 Account with id CD34 and balance 44500 Class Declaration Constructor Creating Objects
151.
152.
© Garth Gilmour
2008 package Account; sub new { my $packageName = shift; my $data = {}; $data->{'id'} = shift; $data->{'balance'} = shift; bless $data, $packageName; } sub withdraw { my $data = shift; $data->{'balance'} -= $_[0]; } sub display { my $data = shift; print "Account with id $data->{'id'} and balance $data->{'balance'}"; } Packages double as classes Any method can be a constructor Anonymous hashes hold fields
153.
© Garth Gilmour
2008 $account1 = Account->new("AB12",30000); $account2 = Account->new("CD34",45000); print "----- Before Withdrawl -----"; $account1->display(); $account2->display(); $account1->withdraw(250); $account2->withdraw(500); print "----- After Withdrawl -----"; $account1->display(); $account2->display(); ----- Before Withdrawl ----- Account with id AB12 and balance 30000 Account with id CD34 and balance