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

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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 DevelopmentsTrustArc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 productivityPrincipled Technologies
 
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 RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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...Neo4j
 

Último (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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 ...
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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...
 

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)