SlideShare uma empresa Scribd logo
1 de 152
Introduction to Perl Dave Cross Magnum Solutions Ltd [email_address]
What We Will Cover ,[object Object]
Creating and running a Perl program
Getting help
Input and Output
Perl variables
Operators and Functions
What We Will Cover ,[object Object]
Subroutines
Regular Expressions
Smart Matching
Finding and using Modules
Schedule ,[object Object]
11:15 – Coffee break (15 mins)
13:00 – Lunch (60 mins)
14:00 – Begin
15:30 – Coffee break (15 mins)
17:00 – End
Resources ,[object Object]
What is Perl?
Perl's Name ,[object Object]
Pathologically Eclectic Rubbish Lister
“Perl” is the language
“perl” is the compiler
Never “PERL”
Typical Uses of Perl ,[object Object]
System administration tasks
CGI and web programming
Database interaction
Other Internet programming
Less Typical Uses of Perl ,[object Object]
NASA
What is Perl Like? ,[object Object]
Free (open source)‏
Fast
Flexible
Secure
Fun
The Perl Philosophy ,[object Object]
Three virtues of a programmer ,[object Object]
Impatience
Hubris ,[object Object]
Creating and Running a Perl Program
Creating a Perl Program ,[object Object]
print "Hello world";
Put this in a file called hello.pl
Running a Perl Program ,[object Object]
$ perl hello.pl
Running a Perl Program ,[object Object]
#!/usr/bin/perl
Make program executable
$ chmod +x hello.pl
Run from command line
$ ./hello.pl
Perl Comments ,[object Object]
Start with a hash (#)‏
Continue to end of line
# This is a hello world program print "Hello, world!"; # print
Command Line Options ,[object Object]
For example, -w turns on warnings
Use on command line
perl -w hello.pl
Or on shebang line
#!/usr/bin/perl -w
More usually  use warnings
Getting Help
Perl Documentation ,[object Object]
Accessed through the  perldoc  command
perldoc perl
perldoc perltoc  – table of contents
Also online at http://perldoc.perl.org/
Lots of references through the course
Some Useful Pages ,[object Object]
perldata
perlsyn
perlfaq
perlstyle
perlcheat
Many many more
Perl Variables
What is a Variable? ,[object Object]
A variable needs a name ,[object Object]
To retrieve the data stored in it
Variable Names ,[object Object]
User variable names may not start with numbers
Variable names are preceded by a punctuation mark indicating the type of data
Types of Perl Variable ,[object Object]
Array variables start with @
Hash variables start with % ,[object Object]
Declaring Variables ,[object Object]
But it's a very good idea ,[object Object]
scoping ,[object Object]
use strict; my $var;
Scalar Variables ,[object Object]
my $name = "Arthur";
my $whoami =   'Just Another Perl Hacker';
my $meaning_of_life = 42;
my $number_less_than_1 = 0.000001;
my $very_large_number = 3.27e17;  # 3.27 times 10 to the power of 17
Type Conversions ,[object Object]
Add int to a floating point number
my $sum = $meaning_of_life +   $number_less_than_1;
Putting a number into a string
print "$name says, 'The meaning of life is $sum.'";
Quoting Strings ,[object Object]
my $price = '$9.95';
Double quotes do
my $invline =   "24 widgets @ $price each";
Backslashes ,[object Object]
print "He said amp;quot;The price is  300amp;quot;";
This can look ugly
Better Quotes ,[object Object]
print qq(He said "The price is 300");
Also works for single quotes
print q(He said "That's too expensive");
Undefined Values ,[object Object]
Test for it with  defined()  function
if (defined($my_var)) { ... }
Array Variables ,[object Object]
my @fruit = ('apples', 'oranges',   'guavas', 'passionfruit',   'grapes');
my @magic_numbers = (23, 42, 69);
my @random_scalars = ('mumble', 123.45,   'dave cross',   -300, $name);
Array Elements ,[object Object]
print $fruits[0]; # prints "apples"
Note: Indexes start from zero
print $random_scalars[2]; # prints "dave cross"
Note use of $ as individual element of an array is a scalar
Array Slices ,[object Object]
print @fruits[0,2,4]; # prints "apples", "guavas", # "grapes"
print @fruits[1 .. 3]; # prints "oranges", "guavas", # "passionfruit"
Note use of @ as we are accessing more than one element of the array
Setting Array Values ,[object Object]
$array[400] = 'something else';
Also with slices
@array[4, 7 .. 9] = ('four','seven',   'eight','nine');
@array[1, 2] = @array[2, 1];
Doesn't need to be an array ,[object Object]
Array Size ,[object Object]
Therefore  $#array + 1  is the number of elements
$count = @array;
Does the same thing and is easier to understand
Hash Variables ,[object Object]
Initialised with a list
%french = ('one', 'un',   'two', 'deux',   'three', 'trois');
Fat Comma ,[object Object]
%german = (one  => 'ein',   two  => 'zwei',    three => 'drei');
Accessing Hash Values ,[object Object]
print $german{two};
As with arrays, notice the use of $ to indicate that we're accessing a single value
Hash Slices ,[object Object]
Returns a list of elements from a hash
print @french{'one','two','three'}; # prints "un", "deux" & "trois"

Mais conteúdo relacionado

Mais procurados

Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 

Mais procurados (20)

JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Javascript
JavascriptJavascript
Javascript
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
rx-java-presentation
rx-java-presentationrx-java-presentation
rx-java-presentation
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Php array
Php arrayPhp array
Php array
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Mari Memahami PSR (PHP Standards Recommendation)
Mari Memahami PSR (PHP Standards Recommendation)Mari Memahami PSR (PHP Standards Recommendation)
Mari Memahami PSR (PHP Standards Recommendation)
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Serverless Spring 오충현
Serverless Spring 오충현Serverless Spring 오충현
Serverless Spring 오충현
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
recursion2
recursion2recursion2
recursion2
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
C# Strings
C# StringsC# Strings
C# Strings
 

Semelhante a Introduction to Perl

Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
Mohammed Farrag
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Semelhante a Introduction to Perl (20)

Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
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
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
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)
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Php2
Php2Php2
Php2
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented Perl
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Cleancode
CleancodeCleancode
Cleancode
 

Mais 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
 

Mais 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

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
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...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 

Introduction to Perl