SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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 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
 
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
 
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 Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
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 Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Kürzlich hochgeladen (20)

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 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
 
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
 
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 Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
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
 
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 Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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)