SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Perl Tutorial For Novice
         Part 1
    Suresh Solaimuthu
History
• Creator, Maintainer, Chief Architect – Larry
  Wall
• Practical Extraction and Report Language
• Pathologically Eclectic Rubbish Lister
• Pearl
• Features from C, awk, tcl/tk
Basic
•   Use any editor to write a Perl program
•   Extension is .pl
•   Run in Unix as $perl <filename>
•   Make it executable and run as
    $./<filename>
Hello World!
                           • Always the first line
#!/usr/local/bin/perl        is #!<pathtoperl>
print “Hello Worldn”;     • print prints to the
                             standard output
                           • print can also be
                             used for printing
                             into files
Standard Input/Output
• Get the input from the user using <STDIN>
  – $x = <STDIN> gets the input from the user
• Print to the standard output
  – print $x prints the value of $x
  – print “hello “,”world”,”n” prints hello world and newline
    character
  – print “hello ”.”world”.”n” also prints hello world and
    newline character
  – So what's the difference?!?!
Data Types
• Scalar
• Arrays
• Associative
Scalar Variables
• Basic kind
• Can hold both numerics and strings and
  interchangeable
  – Eg.: $temp = ‘hi’
  –      $temp = 9
• Starts with “$” symbol followed by a letter
  and then by letters, numbers or
  underscores
• Case sensitive
Numbers
• Integers and Floats
• Internally, Perl computes with double float
• Integer Literals
  – 25
  – 013 and 13 are different!!!!
• Float Literals
  – 1.3
  – -13e-19 == -1.3E-19
Strings
• Sequence of characters
• Each character is 8-bit
• No limit on size!
String Literals
• Single quoted
  – Anything inside the quotation has no special
    meaning except ' and 
  – 'hey'
  – 'heytwazzup' is heytwazzup
• Double quoted
  – Some characters have special meanings
  – “heytwazzup” is hey wazzup
Scalar Operators
• Numbers
  – Mathematical Operators +,-,/,*,%
  – Comparison Operators <, <=, ==, >=, >, !=
• String
  – Repetition – x
     • “Hey” x 2 = “HeyHey”
  – Concatenation - .
     • “James”.” “.”Bond” = “James Bond”
  – Comparison lt, le, eq, ge, gt, ne
Number <--> String Operators
• Careful with the Operators!

• (1+1) x 3 = 222

• “a” + “b” is not an error

• Be CAREFUL!
Assignment Operators
• Assignment $LHS = $RHS
  – The value on the right is assigned to the left
  – $x = ($y = 13)
  – $x = $y = 13
     • $x and $y has the value 13
• Binary Assignment
  – If the variable in LHS and RHS are same
  – $x = $x + 13  $x += 5
  – Similarly, for other binary operators
Auto [Increment, Decrement]
•   Similar to C
•   For both integers and float
•   ++ operator adds 1 to its operand
•   -- operator subtracts 1 from its operand
•   $x = $y++ is different from $x = ++$y
Chop and Chomp
• Chop
  – Removes and returns the last character from the
    input
  – $x = “huhn”
  – chop ($x) makes $x = “huh”
  – chop ($x) makes $x = “hu”
• Chomp
  –   Removes only the “n” from the input
  –   $x = “huhn”;
  –   chomp ($x) makes $x = “huh”
  –   chomp ($x) makes $x = “huh”
Array
•   List is ordered scalar data
•   Array holds list
•   No limits
•   Array variable name starts with @
    – @var1
• Individual elements can be accessed
  using $
    – $var1[0] is the first element
Array Examples
• List literals
  – (1,2,3)
  – (“hello”,1,1.2)
  – ($x+$y,10)
  – List constructor
     • (1..5) is (1,2,3,4,5)
• Array
  – @a = (“hey”,”how”,”are”,”you”)
Array Functions
• Sort
  – @x = sort (@y) will sort the array y and store it
    in x
     • @x = sort (“b”,”a”,”c”) will make @x = (“a”,”b”,”c”)
     • @x = sort (3,12,4,15) will make @x = (12,14,3,4)!!
• Sort by number
  – @x = sort {$a <=> $b} (3,12,4,15) will make @x
    = (3,4,12,15)
Array Functions (cont.)
• Reverse reverses the order of the
  elements in the array
  – @x = reverse (3,2,8) will make @x = (8,2,3)
• Chomp removes the “n” from all the
  elements of the array
  – @x = chomp (“hellon”,”heyn”) will make @x =
    (“hello”,”hey”)
Regular Expressions
• Useful and Powerful string manipulation
  functions
• RE is a pattern to be matched against a
  string
• The regular expression is contained within
  slashes and the matching operator is =~
Is it easy?!?
• To find a pattern “hahaha” in a string $x
  – $x =~ /hahaha/
  – If the above statement is true then “hahaha” is
    present in $x
Regular Expression Characters
• Some special regular expression
  characters
  – . Single Character except newline
  – ^ Beginning of line
  – $ End of line
  – * Zero or more of the last character
  – + One of more of the last character
  – ? Zero or one of the last character
Examples
•   p.f
•   ^the
•   end$
•   abac*
•   ^$
Some more symbols
• Square brackets
   – To match any one character inside the bracket
   – Inside the bracket “^” indicates not
   – And “-” indicates between
• Parenthesis
   – To group characters together
• “|”
   – Either or
Examples
•   [aeiou]
•   [^aeiou]
•   [a-z]
•   [0-9]
•   [a-zA-Z0-9]
•   hello|hey
•   (ab)*
Substitution
• $varname =~ s/old/new
  – The regular expression old will be replaced by
    new
• $varname =~ s/old/new/g
  – All the old regular expressions will be replaced
    by new
Split
• Splits a string based on the regular
  expression given
  – @parts = split (/<regExp>/, $x)
  – Eg.: $x = 1:2:3:4
  –      @parts = split (/:/, $x)
  –      @parts = (1,2,3,4)
To be Continued!

Mais conteúdo relacionado

Mais procurados

Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl courseMarc Logghe
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
PHP Lecture 1 - String, Constants, Arrays, Operators
PHP Lecture 1 - String, Constants, Arrays, OperatorsPHP Lecture 1 - String, Constants, Arrays, Operators
PHP Lecture 1 - String, Constants, Arrays, OperatorsAl-Mamun Sarkar
 
PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and PatternsHenry Osborne
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010leo lapworth
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1Rakesh Mukundan
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Mohd Harris Ahmad Jaal
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String FunctionsGeshan Manandhar
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginnersleo lapworth
 

Mais procurados (16)

Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
 
Php array
Php arrayPhp array
Php array
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
PHP 101
PHP 101 PHP 101
PHP 101
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
PHP Lecture 1 - String, Constants, Arrays, Operators
PHP Lecture 1 - String, Constants, Arrays, OperatorsPHP Lecture 1 - String, Constants, Arrays, Operators
PHP Lecture 1 - String, Constants, Arrays, Operators
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
 
PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and Patterns
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String Functions
 
Python ds
Python dsPython ds
Python ds
 
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
 
1 the ruby way
1   the ruby way1   the ruby way
1 the ruby way
 

Destaque (7)

ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
FrontMatter
FrontMatterFrontMatter
FrontMatter
 
fms9_cwp_php_en
fms9_cwp_php_enfms9_cwp_php_en
fms9_cwp_php_en
 
Day4
Day4Day4
Day4
 
parent_teacher_tutorial
parent_teacher_tutorialparent_teacher_tutorial
parent_teacher_tutorial
 
Jeni Intro1 Bab05 Mendapatkan Input Dari Keyboard
Jeni Intro1 Bab05 Mendapatkan Input Dari KeyboardJeni Intro1 Bab05 Mendapatkan Input Dari Keyboard
Jeni Intro1 Bab05 Mendapatkan Input Dari Keyboard
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 

Semelhante a Perl_Tutorial_v1

Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersGil Megidish
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perlworr1244
 
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...Andrea Telatin
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programmingThang Nguyen
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learningASIT Education
 

Semelhante a Perl_Tutorial_v1 (20)

Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
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...
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programming
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 

Mais de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Mais de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Último

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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 organizationRadu Cotescu
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Último (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Perl_Tutorial_v1

  • 1. Perl Tutorial For Novice Part 1 Suresh Solaimuthu
  • 2. History • Creator, Maintainer, Chief Architect – Larry Wall • Practical Extraction and Report Language • Pathologically Eclectic Rubbish Lister • Pearl • Features from C, awk, tcl/tk
  • 3. Basic • Use any editor to write a Perl program • Extension is .pl • Run in Unix as $perl <filename> • Make it executable and run as $./<filename>
  • 4. Hello World! • Always the first line #!/usr/local/bin/perl is #!<pathtoperl> print “Hello Worldn”; • print prints to the standard output • print can also be used for printing into files
  • 5. Standard Input/Output • Get the input from the user using <STDIN> – $x = <STDIN> gets the input from the user • Print to the standard output – print $x prints the value of $x – print “hello “,”world”,”n” prints hello world and newline character – print “hello ”.”world”.”n” also prints hello world and newline character – So what's the difference?!?!
  • 6. Data Types • Scalar • Arrays • Associative
  • 7. Scalar Variables • Basic kind • Can hold both numerics and strings and interchangeable – Eg.: $temp = ‘hi’ – $temp = 9 • Starts with “$” symbol followed by a letter and then by letters, numbers or underscores • Case sensitive
  • 8. Numbers • Integers and Floats • Internally, Perl computes with double float • Integer Literals – 25 – 013 and 13 are different!!!! • Float Literals – 1.3 – -13e-19 == -1.3E-19
  • 9. Strings • Sequence of characters • Each character is 8-bit • No limit on size!
  • 10. String Literals • Single quoted – Anything inside the quotation has no special meaning except ' and – 'hey' – 'heytwazzup' is heytwazzup • Double quoted – Some characters have special meanings – “heytwazzup” is hey wazzup
  • 11. Scalar Operators • Numbers – Mathematical Operators +,-,/,*,% – Comparison Operators <, <=, ==, >=, >, != • String – Repetition – x • “Hey” x 2 = “HeyHey” – Concatenation - . • “James”.” “.”Bond” = “James Bond” – Comparison lt, le, eq, ge, gt, ne
  • 12. Number <--> String Operators • Careful with the Operators! • (1+1) x 3 = 222 • “a” + “b” is not an error • Be CAREFUL!
  • 13. Assignment Operators • Assignment $LHS = $RHS – The value on the right is assigned to the left – $x = ($y = 13) – $x = $y = 13 • $x and $y has the value 13 • Binary Assignment – If the variable in LHS and RHS are same – $x = $x + 13  $x += 5 – Similarly, for other binary operators
  • 14. Auto [Increment, Decrement] • Similar to C • For both integers and float • ++ operator adds 1 to its operand • -- operator subtracts 1 from its operand • $x = $y++ is different from $x = ++$y
  • 15. Chop and Chomp • Chop – Removes and returns the last character from the input – $x = “huhn” – chop ($x) makes $x = “huh” – chop ($x) makes $x = “hu” • Chomp – Removes only the “n” from the input – $x = “huhn”; – chomp ($x) makes $x = “huh” – chomp ($x) makes $x = “huh”
  • 16. Array • List is ordered scalar data • Array holds list • No limits • Array variable name starts with @ – @var1 • Individual elements can be accessed using $ – $var1[0] is the first element
  • 17. Array Examples • List literals – (1,2,3) – (“hello”,1,1.2) – ($x+$y,10) – List constructor • (1..5) is (1,2,3,4,5) • Array – @a = (“hey”,”how”,”are”,”you”)
  • 18. Array Functions • Sort – @x = sort (@y) will sort the array y and store it in x • @x = sort (“b”,”a”,”c”) will make @x = (“a”,”b”,”c”) • @x = sort (3,12,4,15) will make @x = (12,14,3,4)!! • Sort by number – @x = sort {$a <=> $b} (3,12,4,15) will make @x = (3,4,12,15)
  • 19. Array Functions (cont.) • Reverse reverses the order of the elements in the array – @x = reverse (3,2,8) will make @x = (8,2,3) • Chomp removes the “n” from all the elements of the array – @x = chomp (“hellon”,”heyn”) will make @x = (“hello”,”hey”)
  • 20. Regular Expressions • Useful and Powerful string manipulation functions • RE is a pattern to be matched against a string • The regular expression is contained within slashes and the matching operator is =~
  • 21. Is it easy?!? • To find a pattern “hahaha” in a string $x – $x =~ /hahaha/ – If the above statement is true then “hahaha” is present in $x
  • 22. Regular Expression Characters • Some special regular expression characters – . Single Character except newline – ^ Beginning of line – $ End of line – * Zero or more of the last character – + One of more of the last character – ? Zero or one of the last character
  • 23. Examples • p.f • ^the • end$ • abac* • ^$
  • 24. Some more symbols • Square brackets – To match any one character inside the bracket – Inside the bracket “^” indicates not – And “-” indicates between • Parenthesis – To group characters together • “|” – Either or
  • 25. Examples • [aeiou] • [^aeiou] • [a-z] • [0-9] • [a-zA-Z0-9] • hello|hey • (ab)*
  • 26. Substitution • $varname =~ s/old/new – The regular expression old will be replaced by new • $varname =~ s/old/new/g – All the old regular expressions will be replaced by new
  • 27. Split • Splits a string based on the regular expression given – @parts = split (/<regExp>/, $x) – Eg.: $x = 1:2:3:4 – @parts = split (/:/, $x) – @parts = (1,2,3,4)