SlideShare a Scribd company logo
PERLPERL
Practical Extraction & Reporting LanguagePractical Extraction & Reporting Language
History
Developed by Larry Wall in
1987.
A combination of C and Unix
Shell programming language.
Originally developed for UNIX,
but now runs under all OS.
“A good perl program is one that gets the job
done before your boss fires you.”
Larry Wall, the creator of Perl.
Contents
Introduction
Variables
Operators
Conditional Statements and Loops
Regular Expressions
Subroutines
File Handling
Many more....
File Management Contd..
binmode(HANDLE): change file mode from text to binary
unlink("myfile"): delete file myfile
rename("file1","file2"): change name of file file1 to file2
mkdir("mydir"): create directory mydir
rmdir("mydir"): delete directory mydir
chdir("mydir"): change the current directory to mydir
system("command"): execute command command
die("message"): exit program with message message
warn("message"): warn user about problem message
Introduction
Interpreted language, optimized for string manipulation, I/O and
system tasks.
Speed of development
Easy to use, portable
Freely available
Extension is .pl
Execution : perl file.pl
All perl program goes through 2 phases :
a compile phase where the syntax is checked and the source code,
including any modules used, is converted into bytecode.
a run-time phase where the bytecode is processed into machine
instructions and executed.
Basic Syntax
All statements should end with ';'
# is used for commenting a line
Perl is case sensitive
Basic options : -c, -v, -w
Variables
Three basic data types, scalars, arrays and hashes
Scalars : Holds a single value of any type.
$var1 = 123
$var2 = “Hello, how r u”
$var3 = 1.23
$1var = 123 # Error
Built-in Functions
Chomp() : The chomp() function will remove (usually) any newline
character from the end of a string.
Chop() : The chop() function will remove the last character of a string
(or group of strings) regardless of what that character is.
Control Flow
Syntax same as C
If Construct :
if (expr) {
stmt block;
}
If Else Construct :
Loops
Loops in Perl are written in the same way as in C.
Only remember that the loop variable is a scalar variable and must be
preceded by a $ sign.
while (expr) {
stmt block;
}
do {
stmt block;
} while (expr);
for (expr1 ; expr2 ; expr3) {
stmt block;
}
foreach var (listexpr) {
Foreach
Behaves same as for loop.
foreach $person (@names) {
print "$person";
}
$_ : Default Input and Pattern Searching Variable
foreach (@names) {
print "$_";
}
Lists
List is a group of scalars used to initialize and array or hash.
Elements can be any type of scalar data.
List functions :
Join : Joins list values
Split : A string is splited
Map : Evaluates expression or blocks
Grep : Returns a sublist of list for each a specific criteria is true
Arrays
In Perl an array does not have to be declared before it is used.
The size of an array increases dynamically.
An array variable has an @ before it.
@num = (1,2,3,4,5);
@num = (1..5);
@mix_arr = ("Tom", 5, "Cruise", 90, "Jane", 35.67 34, 78, "I am Bond");
You can assign an array element to any index - even one that is
beyond the current range of index numbers.
The in-between elements are assigned null values.
Push, Pop and Splice
The push function pushes an element onto an array. If the last element in
an array has index 5, pushing an element onto the array makes it the
element with index 6.
The syntax is:
push(@arrayname, value);
The pop function pops off the last element off the array. So, if the last
element in the array @myarray is 99, then the statement
$num = pop(@myarray);
assigns the value 99 to $num.
The splice function is used to pop more than one element.
(splice(@myarray, -3)
Unshift and Shift
These work like the push and pop operators, but add and subtract from
the beginning of an array rather than the end.
The syntax is
unshift(@arrayname, value);
shift(@arrayname);
Associative Array or Hash
Hashes are a list of scalars, but instead of being accessed by index
number, they are accessed by a key.
Syntax : %myhash = ('Key1', 'Val1', 'Key2', 'Val2', 'Key3', 'Val3')
Index No Value
0 Spain
1 Belgium
2 Germany
3 Netherlan
ds
Key Value
SP Spain
BL Belgium
GE Germany
NL Netherland
s
Perl Command Line
Read from command prompt.
Go to example.
Hash Functions
Assigning : $countries{PT} = 'Portugal';
Deleting : delete $countries{NL};
Print all the keys : print keys %countries;
Print all the values : print values %countries;
A slice of hash : print @countries{'NL', 'BL'};
How many elements : print scalar(keys %countries);
Does the key exist : print “I exist n” if exists $countries{'NL'};
Subroutine
Syntax for subroutines :
Sub subname {
Stmt block;
}
Value of the last expression evaluated by the subroutine is automatically
considered to be subroutine's return value.
Foreach $var (&subname) {
Stmt block;
}
Perl defines 3 special subroutines that are executed at specific times.
BEGIN : Called when our program starts running.
END : Called when the program terminates.
AUTOLOAD : Called when the program cannot find a subroutine it is
File Management
open(INFILE,"myfile"): reading
open(OUTFILE,">myfile"): writing
open(OUTFILE,">>myfile"): appending
open(INFILE,"someprogram |"): reading from program
open(OUTFILE,"| someprogram"): writing to program
opendir(DIR,"mydirectory"): open directo
Operations on an open file handle
$a = <INFILE>: read a line from INFILE into $a
@a = <INFILE>: read all lines from INFILE into @a
$a = readdir(DIR): read a filename from DIR into $a
@a = readdir(DIR): read all filenames from DIR into @a
read(INFILE,$a,$length): read $length characters from INFILE into $a
print OUTFILE "text": write some text in OUTFILE
Close files / directories
Perl Debugger
Perl -d myprogram.pl
Debugger commands :
l : lists the next few statements.
l 10 : specifies the line number
l 10-15 : display a range of lines
l subroutine : display subroutine
- : display the immediately preceding the last displayed line
/search'/ : Search for a line containing the pattern
?backsearch? : To search backword for a pattern
S : lists all the subroutines in the file
s : execute single statement and displays next statement to execute
n : same as s command, but n command does not enter subroutine,
directly execute it
r : if we are inside a subroutine and do not want to execute further, this
command finishes subroutine execution and returns to the last
statement called the subroutine
X : print the value of a particular variable
Resources
Perl.com
Perl.org
Lists.perl.org
Perlmonks
Stackoverflow
Perl mongers
Search.cpan.org
Continued...

More Related Content

What's hot

Perl names values and variables
Perl names values and variablesPerl names values and variables
Perl names values and variables
sana mateen
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
marcheiligers
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
Mohammad Alyan
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
Sandeep Kr. Singh
 
Lists and arrays
Lists and arraysLists and arrays
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
Henri Tremblay
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
AtreyiB
 
Implode & Explode in PHP
Implode & Explode in PHPImplode & Explode in PHP
Implode & Explode in PHP
Vineet Kumar Saini
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
Mark Baker
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1
Nihar Ranjan Paital
 
Perl
PerlPerl
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
Nihar Ranjan Paital
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Arrays in linux
Arrays in linuxArrays in linux
Arrays in linux
Whaleejaa Wha
 
The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184
Mahmoud Samir Fayed
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
Nihar Ranjan Paital
 
Perl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally InsanePerl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally Insane
Ricardo Signes
 
Subroutines
SubroutinesSubroutines
Subroutines
primeteacher32
 

What's hot (20)

Perl names values and variables
Perl names values and variablesPerl names values and variables
Perl names values and variables
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Implode & Explode in PHP
Implode & Explode in PHPImplode & Explode in PHP
Implode & Explode in PHP
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1
 
Perl
PerlPerl
Perl
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
Arrays in linux
Arrays in linuxArrays in linux
Arrays in linux
 
The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
Perl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally InsanePerl 5.10 for People Who Aren't Totally Insane
Perl 5.10 for People Who Aren't Totally Insane
 
Subroutines
SubroutinesSubroutines
Subroutines
 

Similar to Perl

Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
Nithin Kumar Singani
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Mufaddal Haidermota
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
Ganesh Samarthyam
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
Gaurav Bisht
 
Perl_Part6
Perl_Part6Perl_Part6
Perl_Part6
Frank Booth
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
Advanced perl finer points ,pack&amp;unpack,eval,files
Advanced perl   finer points ,pack&amp;unpack,eval,filesAdvanced perl   finer points ,pack&amp;unpack,eval,files
Advanced perl finer points ,pack&amp;unpack,eval,files
Shankar D
 
Perl tutorial final
Perl tutorial finalPerl tutorial final
Perl tutorial final
Ashoka Vanjare
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
Gaurav Shinde
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
 
Using Unix
Using UnixUsing Unix
Using Unix
Dr.Ravi
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
Tim Essam
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
Prof. Wim Van Criekinge
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
Artem Nagornyi
 
1. python
1. python1. python
1. python
PRASHANT OJHA
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
Lahore Garrison University
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
O T
 

Similar to Perl (20)

Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
 
Perl_Part6
Perl_Part6Perl_Part6
Perl_Part6
 
Shell programming
Shell programmingShell programming
Shell programming
 
Advanced perl finer points ,pack&amp;unpack,eval,files
Advanced perl   finer points ,pack&amp;unpack,eval,filesAdvanced perl   finer points ,pack&amp;unpack,eval,files
Advanced perl finer points ,pack&amp;unpack,eval,files
 
Perl tutorial final
Perl tutorial finalPerl tutorial final
Perl tutorial final
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
1. python
1. python1. python
1. python
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 

Recently uploaded

Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 

Perl

  • 1. PERLPERL Practical Extraction & Reporting LanguagePractical Extraction & Reporting Language
  • 2. History Developed by Larry Wall in 1987. A combination of C and Unix Shell programming language. Originally developed for UNIX, but now runs under all OS. “A good perl program is one that gets the job done before your boss fires you.” Larry Wall, the creator of Perl.
  • 3. Contents Introduction Variables Operators Conditional Statements and Loops Regular Expressions Subroutines File Handling Many more....
  • 4. File Management Contd.. binmode(HANDLE): change file mode from text to binary unlink("myfile"): delete file myfile rename("file1","file2"): change name of file file1 to file2 mkdir("mydir"): create directory mydir rmdir("mydir"): delete directory mydir chdir("mydir"): change the current directory to mydir system("command"): execute command command die("message"): exit program with message message warn("message"): warn user about problem message
  • 5. Introduction Interpreted language, optimized for string manipulation, I/O and system tasks. Speed of development Easy to use, portable Freely available Extension is .pl Execution : perl file.pl All perl program goes through 2 phases : a compile phase where the syntax is checked and the source code, including any modules used, is converted into bytecode. a run-time phase where the bytecode is processed into machine instructions and executed.
  • 6. Basic Syntax All statements should end with ';' # is used for commenting a line Perl is case sensitive Basic options : -c, -v, -w
  • 7. Variables Three basic data types, scalars, arrays and hashes Scalars : Holds a single value of any type. $var1 = 123 $var2 = “Hello, how r u” $var3 = 1.23 $1var = 123 # Error
  • 8. Built-in Functions Chomp() : The chomp() function will remove (usually) any newline character from the end of a string. Chop() : The chop() function will remove the last character of a string (or group of strings) regardless of what that character is.
  • 9. Control Flow Syntax same as C If Construct : if (expr) { stmt block; } If Else Construct :
  • 10. Loops Loops in Perl are written in the same way as in C. Only remember that the loop variable is a scalar variable and must be preceded by a $ sign. while (expr) { stmt block; } do { stmt block; } while (expr); for (expr1 ; expr2 ; expr3) { stmt block; } foreach var (listexpr) {
  • 11. Foreach Behaves same as for loop. foreach $person (@names) { print "$person"; } $_ : Default Input and Pattern Searching Variable foreach (@names) { print "$_"; }
  • 12. Lists List is a group of scalars used to initialize and array or hash. Elements can be any type of scalar data. List functions : Join : Joins list values Split : A string is splited Map : Evaluates expression or blocks Grep : Returns a sublist of list for each a specific criteria is true
  • 13. Arrays In Perl an array does not have to be declared before it is used. The size of an array increases dynamically. An array variable has an @ before it. @num = (1,2,3,4,5); @num = (1..5); @mix_arr = ("Tom", 5, "Cruise", 90, "Jane", 35.67 34, 78, "I am Bond"); You can assign an array element to any index - even one that is beyond the current range of index numbers. The in-between elements are assigned null values.
  • 14. Push, Pop and Splice The push function pushes an element onto an array. If the last element in an array has index 5, pushing an element onto the array makes it the element with index 6. The syntax is: push(@arrayname, value); The pop function pops off the last element off the array. So, if the last element in the array @myarray is 99, then the statement $num = pop(@myarray); assigns the value 99 to $num. The splice function is used to pop more than one element. (splice(@myarray, -3)
  • 15. Unshift and Shift These work like the push and pop operators, but add and subtract from the beginning of an array rather than the end. The syntax is unshift(@arrayname, value); shift(@arrayname);
  • 16. Associative Array or Hash Hashes are a list of scalars, but instead of being accessed by index number, they are accessed by a key. Syntax : %myhash = ('Key1', 'Val1', 'Key2', 'Val2', 'Key3', 'Val3') Index No Value 0 Spain 1 Belgium 2 Germany 3 Netherlan ds Key Value SP Spain BL Belgium GE Germany NL Netherland s
  • 17. Perl Command Line Read from command prompt. Go to example.
  • 18. Hash Functions Assigning : $countries{PT} = 'Portugal'; Deleting : delete $countries{NL}; Print all the keys : print keys %countries; Print all the values : print values %countries; A slice of hash : print @countries{'NL', 'BL'}; How many elements : print scalar(keys %countries); Does the key exist : print “I exist n” if exists $countries{'NL'};
  • 19. Subroutine Syntax for subroutines : Sub subname { Stmt block; } Value of the last expression evaluated by the subroutine is automatically considered to be subroutine's return value. Foreach $var (&subname) { Stmt block; } Perl defines 3 special subroutines that are executed at specific times. BEGIN : Called when our program starts running. END : Called when the program terminates. AUTOLOAD : Called when the program cannot find a subroutine it is
  • 20. File Management open(INFILE,"myfile"): reading open(OUTFILE,">myfile"): writing open(OUTFILE,">>myfile"): appending open(INFILE,"someprogram |"): reading from program open(OUTFILE,"| someprogram"): writing to program opendir(DIR,"mydirectory"): open directo Operations on an open file handle $a = <INFILE>: read a line from INFILE into $a @a = <INFILE>: read all lines from INFILE into @a $a = readdir(DIR): read a filename from DIR into $a @a = readdir(DIR): read all filenames from DIR into @a read(INFILE,$a,$length): read $length characters from INFILE into $a print OUTFILE "text": write some text in OUTFILE Close files / directories
  • 21. Perl Debugger Perl -d myprogram.pl Debugger commands : l : lists the next few statements. l 10 : specifies the line number l 10-15 : display a range of lines l subroutine : display subroutine - : display the immediately preceding the last displayed line /search'/ : Search for a line containing the pattern ?backsearch? : To search backword for a pattern S : lists all the subroutines in the file s : execute single statement and displays next statement to execute n : same as s command, but n command does not enter subroutine, directly execute it r : if we are inside a subroutine and do not want to execute further, this command finishes subroutine execution and returns to the last statement called the subroutine X : print the value of a particular variable