SlideShare a Scribd company logo
PERL
(PRACTICAL REPORT AND EXTRACTION
LANGUAGE)
Session-1
INTRODUCTION
What is PERL?
* Practical extraction and report language.
* It is an interpreted language, optimized
for scanning arbitrary text files, extracting
information from them, and printing reports
based on that information.
* Very powerful string handling features.
* Available on all platforms.
ADVANTAGES
*Speed:-As it is an interpretive
language;no need of compiler.Only we
enter the program in the text file and just
run it.
*The regular expressions of Perl are
extremely powerful.
*Uses sophisticated pattern matching
techniques to scan large amounts of data
very quickly.
*Portability:-Perl is a standard
language and is available on all
platforms.
-Free versions are available
on the internet.
*Editing Perl programs:-No
sophiticated editing tool is needed.
-Any simple text editor
like notepad or vi will do.
*Flexibility:-Perl does not limit
the size of your data.
-If memory is available
,Perl can handle the whole file as
a single string.
-Allows one to write
simple programs to perform
complex tasks.
How to run Perl?
*Perl can be downloaded from the internet.
*Available on almost all platforms.
Assumptions:-
*For windows operating system,we can run Perl
program from command prompt.
-Rum "cmd" to get command prompt window.
*For Unix/Linux,we can run directly from the shell
prompt.
EXAMPLE
*For Windows
-Create a directory/folder where you will be
storing the Perl files.
-Using any text editor create a file "first.pl"
with the following content:
print "Good morning Indian";
print "This is my first Perl programn";
-Execute the program by typing the
following at the command prompt:
perl first.pl
*On Unix/Linux,an additional line has to be
given at the beginning of every Perl
program.
#!/usr/bin/perl
print "Good dayn";
print "This is my first Perl programn";
Variables
*Scalar variables
-A scalar variable holds a single value.
-Other variable types are also available which
are
(a)Array
(b)Associative array
-A '$'is used before the name of a variable to
indicate that it is a scalar variable
$x=100;
*Some examples:
$x=100;
$name="Suman Ghosh";
$average=56.98;
* Variables do not have any fixed types.
*Variables can be printed as:
print"MY name is $name,the average marks
obtained is $averagen";
* Data types:
*Perl does not specify the types of
variables.
-It is a loosly typed language.
-Languages like C or java are strongly
typed.
*An example:
$stud="Rahul";
$marks=86;
print"Marks obtained by $stud is $marksn";
print'Marks obtained by $stud is $marksn';
*The program will give the following
output:
Marks obtained by Rahul is 89
Marks obtained by $stud is $marksn
*What do we saw:-
-If we need to do variable interpolation,use
double quotes;otherwise ,use single quotes.
*Another example:
$expense='$10';
print"The expenditure is $expensen";
The output is
The expenditure is $10
If $10 is within double-quotes than the
perl interpreter may get confused any
will try to find the value of variable
100.
Expressions with Scalars
*Illustrated through examples(syntax similar to C)
$a=89;
$a++;
$b=100;
$total;
$a=$b**10; #exponentiation
$a=b%10; #modulus
$balance=$balance+Sdeposit;
$balance +=balance;
*Program in Unix/Linux
#!/usr/bin/perl
$a=89;
print "the value of a is $an";
$a++;
print "the incremented value of a is $an";
$b=100;
print "the value of b is $bn";
$total=$a+$b;
print"the total value is $totaln";
$a=$b**2; #exponentiation
print "the value of a is $an";
$b=a%10; #modulus
print "the value of b is $bn";
*Output of above program is:
the value of a is 89
the incremented value of a is 90
the value of b is 100
the total value is 190
the value of a is 1e+20
the value of b is 0
*Operations on strings:
-Concatenation :the dot (.) is used.
$a="Good";
$b="day";
$c="n";
$total=$a.$b.$c; #Concatenate the
strings
$a .="nightn"; #add to the string $a
*Example
!/usr/bin/perl
$a="Welcome to";
$b=" ASILICON DESIGN";
$c="n";
$total=$a.$b.$c; #Concatenate the
strings
print" total is $totaln";
$a .=" Asilicon familyn"; #add to the
string $a
print"the value of a is $a";
Output of above program is:
total is Welcome to ASILICON DESIGN
the value of a is Welcome to Asilicon family
*Arithmetic operation on strings
$a="bat";
$b=$a+1;
print$a." and ".$b;
will print bat and cat
*Operations carried out based on ASCII codes.
-May not be always meaningful.
*String repetation operator(x).
$a=Sbx4;
will concatenate four copies of $b and
assign to $a.
print "Ba"."na"x2;
will print the string "banana".
*Example
#!/usr/bin/perl
$a="anocon";
$b="da";
$y=$a.$b;
print "$yn";
String as a Number
*A string can be used in a arithmetic expression.
-How is the value evaluated?
-When converting a string to a number,Perl takes
any spaces,an optional minus sign,and as many
digits it can find with (with dot) at the begining of
the string,and ignores everything else.
Examples
"89.98" evaluates to 89.98
"4757java789" evaluates to 4757
"apple" evaluates to 0
Examples:-
#!/usr/bin/perl
$a=90;
$b="apes";
$c=$a+$b;
print"the value of c is $cn";
$d="100hyhy89";
$e=$a+$d;
print"the value of e is $en";;
Output of above program is:
the value of a is 90
the value of e is 190
Escaping
*The chracter '' is used as escape chracter.
-It escapes all of perl's special characters(e.g
$,@,#,etc).
Example
#!/usr/bin/perl
$a=100;
print "the value of $a is $an";
Output of above program is
the value of $a is 100
Line Oriented Quoting
*Perl supports specification of a
string spanning multiple lines.
-Use the marker "<<".
-Follow it by a string,which is
used to terminate the quoted
material.
Example 1
#!/usr/bin/perl
print<<terminator;
Hello, John how are you?
Bye,have a nice day.
terminator
Output of above program is
Hello, John how are you?
Bye,have a nice day.
Example2
#!/usr/bin/perl
print<<john;
Welcome home.
How are you.
john
Output of above program is
Welcome home.
How are you.
Lists and Arrays
Basic difference between List and Array
*List is an ordered list of scalars.
*Array is a variable that holds a list.
*Each element of an array is a scalar.
*The size of an array:
-Lower limit:0
-Upper limit:No specific limit ;depends on the
virtual memory.
List literals
*Examples:
(10,20,67,190,187)
('red',"blue","green")
("a",1,9,7,'h')
($a,89)
() #empty list
(80..90) #list constructor function
('A'..'Z') #same,for letters
Specifying Array Variable
*we use the special character '@'.
@day #denotes an array
@x #denotes an array
The individual elements of the array are
scalars,and can be referred to as:
@day[0] #first element of @day
@day[1] #second element of @day
Initializing an Array
*Two ways:
-specify values,separated by commas.
@color=('red','green','blue','black');
-Use the quote words(qw) function ,that
uses space as the delimiter:
@color=qw(red green blue black);
Example-1
#!usr/bin/perl
$a=8;
$b=7;
$c=98;
$d=45;
@num=($a,$b,$c,$d);
print"the value of num array is @numn";;
Output of above example is
the value of num array is 8 7 98 45
Example 2
#!/usr/bin/perl
@color=qw(red green yellow black);
print "the value of first element is @color[0]n";
print "the value of second element is @color[1]n";
print "the value of third element is @color[2]n";
print "the value of fourth element is @color[3]n";
print"the value of color array is @colorn";
Output of above program is
the value of first element is red
the value of second element is green
the value of third element is yellow
the value of fourth element is black
the value of color array is red green yellow black
Thank You

More Related Content

DOCX
PERL for QA - Important Commands and applications
PDF
perltut
PDF
perltut
ODP
Beginning Perl
ODP
Introduction to Perl
PDF
newperl5
PDF
newperl5
PPT
Introduction to perl scripting______.ppt
PERL for QA - Important Commands and applications
perltut
perltut
Beginning Perl
Introduction to Perl
newperl5
newperl5
Introduction to perl scripting______.ppt

Similar to PERL.ppt (20)

ODP
Introduction to Perl - Day 1
PPT
Perl Basics with Examples
PPT
LPW: Beginners Perl
PPTX
Perl slid
PPT
Introduction to Perl
PDF
Tutorial perl programming basic eng ver
PPT
Perl tutorial
PPT
Perl Programming_Guide_Document_Refr.ppt
PPT
Crash Course in Perl – Perl tutorial for C programmers
PDF
Practical approach to perl day1
PPT
Learn perl in amc square learning
PPTX
Perl courseparti
PDF
Scripting3
PPTX
Intro to Perl
PPTX
PERL PROGRAMMING LANGUAGE Basic Introduction
PPT
PERL - complete_Training_Modules_Ref.ppt
PPT
PERL - complete_guide_references (1).ppt
PDF
Cs3430 lecture 15
ODP
Perl Introduction
PPT
Introduction to perl_ a scripting language
Introduction to Perl - Day 1
Perl Basics with Examples
LPW: Beginners Perl
Perl slid
Introduction to Perl
Tutorial perl programming basic eng ver
Perl tutorial
Perl Programming_Guide_Document_Refr.ppt
Crash Course in Perl – Perl tutorial for C programmers
Practical approach to perl day1
Learn perl in amc square learning
Perl courseparti
Scripting3
Intro to Perl
PERL PROGRAMMING LANGUAGE Basic Introduction
PERL - complete_Training_Modules_Ref.ppt
PERL - complete_guide_references (1).ppt
Cs3430 lecture 15
Perl Introduction
Introduction to perl_ a scripting language
Ad

Recently uploaded (20)

PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
PPT on Performance Review to get promotions
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
additive manufacturing of ss316l using mig welding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Project quality management in manufacturing
PPTX
Geodesy 1.pptx...............................................
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Well-logging-methods_new................
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Digital Logic Computer Design lecture notes
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT on Performance Review to get promotions
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
additive manufacturing of ss316l using mig welding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
OOP with Java - Java Introduction (Basics)
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Project quality management in manufacturing
Geodesy 1.pptx...............................................
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Well-logging-methods_new................
Ad

PERL.ppt

  • 1. PERL (PRACTICAL REPORT AND EXTRACTION LANGUAGE) Session-1
  • 2. INTRODUCTION What is PERL? * Practical extraction and report language. * It is an interpreted language, optimized for scanning arbitrary text files, extracting information from them, and printing reports based on that information. * Very powerful string handling features. * Available on all platforms.
  • 3. ADVANTAGES *Speed:-As it is an interpretive language;no need of compiler.Only we enter the program in the text file and just run it. *The regular expressions of Perl are extremely powerful. *Uses sophisticated pattern matching techniques to scan large amounts of data very quickly.
  • 4. *Portability:-Perl is a standard language and is available on all platforms. -Free versions are available on the internet. *Editing Perl programs:-No sophiticated editing tool is needed. -Any simple text editor like notepad or vi will do.
  • 5. *Flexibility:-Perl does not limit the size of your data. -If memory is available ,Perl can handle the whole file as a single string. -Allows one to write simple programs to perform complex tasks.
  • 6. How to run Perl? *Perl can be downloaded from the internet. *Available on almost all platforms. Assumptions:- *For windows operating system,we can run Perl program from command prompt. -Rum "cmd" to get command prompt window. *For Unix/Linux,we can run directly from the shell prompt.
  • 7. EXAMPLE *For Windows -Create a directory/folder where you will be storing the Perl files. -Using any text editor create a file "first.pl" with the following content: print "Good morning Indian"; print "This is my first Perl programn"; -Execute the program by typing the following at the command prompt: perl first.pl
  • 8. *On Unix/Linux,an additional line has to be given at the beginning of every Perl program. #!/usr/bin/perl print "Good dayn"; print "This is my first Perl programn";
  • 9. Variables *Scalar variables -A scalar variable holds a single value. -Other variable types are also available which are (a)Array (b)Associative array -A '$'is used before the name of a variable to indicate that it is a scalar variable $x=100;
  • 10. *Some examples: $x=100; $name="Suman Ghosh"; $average=56.98; * Variables do not have any fixed types. *Variables can be printed as: print"MY name is $name,the average marks obtained is $averagen";
  • 11. * Data types: *Perl does not specify the types of variables. -It is a loosly typed language. -Languages like C or java are strongly typed.
  • 12. *An example: $stud="Rahul"; $marks=86; print"Marks obtained by $stud is $marksn"; print'Marks obtained by $stud is $marksn';
  • 13. *The program will give the following output: Marks obtained by Rahul is 89 Marks obtained by $stud is $marksn *What do we saw:- -If we need to do variable interpolation,use double quotes;otherwise ,use single quotes.
  • 14. *Another example: $expense='$10'; print"The expenditure is $expensen"; The output is The expenditure is $10 If $10 is within double-quotes than the perl interpreter may get confused any will try to find the value of variable 100.
  • 15. Expressions with Scalars *Illustrated through examples(syntax similar to C) $a=89; $a++; $b=100; $total; $a=$b**10; #exponentiation $a=b%10; #modulus $balance=$balance+Sdeposit; $balance +=balance;
  • 16. *Program in Unix/Linux #!/usr/bin/perl $a=89; print "the value of a is $an"; $a++; print "the incremented value of a is $an"; $b=100; print "the value of b is $bn"; $total=$a+$b; print"the total value is $totaln"; $a=$b**2; #exponentiation print "the value of a is $an"; $b=a%10; #modulus print "the value of b is $bn";
  • 17. *Output of above program is: the value of a is 89 the incremented value of a is 90 the value of b is 100 the total value is 190 the value of a is 1e+20 the value of b is 0
  • 18. *Operations on strings: -Concatenation :the dot (.) is used. $a="Good"; $b="day"; $c="n"; $total=$a.$b.$c; #Concatenate the strings $a .="nightn"; #add to the string $a
  • 19. *Example !/usr/bin/perl $a="Welcome to"; $b=" ASILICON DESIGN"; $c="n"; $total=$a.$b.$c; #Concatenate the strings print" total is $totaln"; $a .=" Asilicon familyn"; #add to the string $a print"the value of a is $a";
  • 20. Output of above program is: total is Welcome to ASILICON DESIGN the value of a is Welcome to Asilicon family
  • 21. *Arithmetic operation on strings $a="bat"; $b=$a+1; print$a." and ".$b; will print bat and cat *Operations carried out based on ASCII codes. -May not be always meaningful.
  • 22. *String repetation operator(x). $a=Sbx4; will concatenate four copies of $b and assign to $a. print "Ba"."na"x2; will print the string "banana".
  • 24. String as a Number *A string can be used in a arithmetic expression. -How is the value evaluated? -When converting a string to a number,Perl takes any spaces,an optional minus sign,and as many digits it can find with (with dot) at the begining of the string,and ignores everything else. Examples "89.98" evaluates to 89.98 "4757java789" evaluates to 4757 "apple" evaluates to 0
  • 25. Examples:- #!/usr/bin/perl $a=90; $b="apes"; $c=$a+$b; print"the value of c is $cn"; $d="100hyhy89"; $e=$a+$d; print"the value of e is $en";;
  • 26. Output of above program is: the value of a is 90 the value of e is 190
  • 27. Escaping *The chracter '' is used as escape chracter. -It escapes all of perl's special characters(e.g $,@,#,etc). Example #!/usr/bin/perl $a=100; print "the value of $a is $an"; Output of above program is the value of $a is 100
  • 28. Line Oriented Quoting *Perl supports specification of a string spanning multiple lines. -Use the marker "<<". -Follow it by a string,which is used to terminate the quoted material.
  • 29. Example 1 #!/usr/bin/perl print<<terminator; Hello, John how are you? Bye,have a nice day. terminator Output of above program is Hello, John how are you? Bye,have a nice day.
  • 30. Example2 #!/usr/bin/perl print<<john; Welcome home. How are you. john Output of above program is Welcome home. How are you.
  • 32. Basic difference between List and Array *List is an ordered list of scalars. *Array is a variable that holds a list. *Each element of an array is a scalar. *The size of an array: -Lower limit:0 -Upper limit:No specific limit ;depends on the virtual memory.
  • 33. List literals *Examples: (10,20,67,190,187) ('red',"blue","green") ("a",1,9,7,'h') ($a,89) () #empty list (80..90) #list constructor function ('A'..'Z') #same,for letters
  • 34. Specifying Array Variable *we use the special character '@'. @day #denotes an array @x #denotes an array The individual elements of the array are scalars,and can be referred to as: @day[0] #first element of @day @day[1] #second element of @day
  • 35. Initializing an Array *Two ways: -specify values,separated by commas. @color=('red','green','blue','black'); -Use the quote words(qw) function ,that uses space as the delimiter: @color=qw(red green blue black);
  • 36. Example-1 #!usr/bin/perl $a=8; $b=7; $c=98; $d=45; @num=($a,$b,$c,$d); print"the value of num array is @numn";; Output of above example is the value of num array is 8 7 98 45
  • 37. Example 2 #!/usr/bin/perl @color=qw(red green yellow black); print "the value of first element is @color[0]n"; print "the value of second element is @color[1]n"; print "the value of third element is @color[2]n"; print "the value of fourth element is @color[3]n"; print"the value of color array is @colorn";
  • 38. Output of above program is the value of first element is red the value of second element is green the value of third element is yellow the value of fourth element is black the value of color array is red green yellow black