SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
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!

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDI
STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDISTUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDI
STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDIgianlkr
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-startedtutorialsruby
 
collapsible-panels-tutorial
collapsible-panels-tutorialcollapsible-panels-tutorial
collapsible-panels-tutorialtutorialsruby
 
indesign_cs3_scripting_tutorial
indesign_cs3_scripting_tutorialindesign_cs3_scripting_tutorial
indesign_cs3_scripting_tutorialtutorialsruby
 
由Hash Set谈重用
由Hash Set谈重用由Hash Set谈重用
由Hash Set谈重用yiditushe
 
Презентация Барто
Презентация БартоПрезентация Барто
Презентация Бартоdalton1k
 
Notebook PMB 2007 Part 1
Notebook PMB 2007 Part 1Notebook PMB 2007 Part 1
Notebook PMB 2007 Part 1Eric Floresca
 

Destacado (19)

netbeans
netbeansnetbeans
netbeans
 
Taula comarcal de salut juvenil de l’Alt Empordà
Taula comarcal de salut juvenil de l’Alt EmpordàTaula comarcal de salut juvenil de l’Alt Empordà
Taula comarcal de salut juvenil de l’Alt Empordà
 
STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDI
STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDISTUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDI
STUDI di SETTORE NOVITÀ del DECRETO «ANTI-CRISI» ed EVOLUZIONE degli STUDI
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-started
 
toc
toctoc
toc
 
40020
4002040020
40020
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
phptut2
phptut2phptut2
phptut2
 
lecture2_public
lecture2_publiclecture2_public
lecture2_public
 
collapsible-panels-tutorial
collapsible-panels-tutorialcollapsible-panels-tutorial
collapsible-panels-tutorial
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
indesign_cs3_scripting_tutorial
indesign_cs3_scripting_tutorialindesign_cs3_scripting_tutorial
indesign_cs3_scripting_tutorial
 
由Hash Set谈重用
由Hash Set谈重用由Hash Set谈重用
由Hash Set谈重用
 
Rahul_Resume ....
Rahul_Resume ....Rahul_Resume ....
Rahul_Resume ....
 
Question 5
Question 5Question 5
Question 5
 
Презентация Барто
Презентация БартоПрезентация Барто
Презентация Барто
 
11 18 Everlasting Flowers2
11 18 Everlasting Flowers211 18 Everlasting Flowers2
11 18 Everlasting Flowers2
 
hailpern-interact09
hailpern-interact09hailpern-interact09
hailpern-interact09
 
Notebook PMB 2007 Part 1
Notebook PMB 2007 Part 1Notebook PMB 2007 Part 1
Notebook PMB 2007 Part 1
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncObject Automation
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum ComputingGDSC PJATK
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 

Último (20)

Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation Inc
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 

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)