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

• (1+1) x 3 = 222

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

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

Mais conteúdo relacionado

Mais procurados

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

Mais procurados (16)

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

Destaque

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
 

Destaque (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
 

Semelhante a Perl_Tutorial_v1

Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersGil Megidish
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perlworr1244
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programmingThang Nguyen
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learningASIT Education
 

Semelhante a Perl_Tutorial_v1 (20)

Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programming
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 

Mais de tutorialsruby

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

Mais de tutorialsruby (20)

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

Último

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Último (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

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)