SlideShare a Scribd company logo
3
Most read
4
Most read
8
Most read
CHARACTERISTICS OF SCRIPTING
LANGUAGE
 Efficiency is not an issue
Ease of use is achieved at the expense of efficiency
eg: interpretation rather than compiling
Focus is not on high performance but on the speed of development together
with ability to make changes to meet new requirement.
6/13/2016 1Introduction to scripts and scripting
INTRODUCTION TO PERL
By
Sana Mateen
6/15/2016
2
PERL—PRACTICAL EXTRACTION
REPORT LANGUAGE
 Perl is a programming language developed by Larry Wall, especially
designed for text processing. Though Perl is not officially an acronym but
many times it is used as it stands for Practical Extraction and Report
Language. It runs on a variety of platforms, such as Windows, Mac OS, and
the various versions of UNIX.
 Perl is a general-purpose programming language originally developed for
text manipulation and now used for a wide range of tasks including system
administration, web development, network programming, GUI
development(wxperl and perl-tk interfaces), and more.
6/15/2016
3
WHAT IS PERL? AND PERL FEATURES ?
1. Perl is a stable, cross platform programming language.
2. Though Perl is not officially an acronym but few people used it as Practical
Extraction and Report Language.
3. It is used for mission critical projects in the public and private sectors.
4. Perl is an Open Source software, licensed under its Artistic License, or the GNU
General Public License (GPL).
5. Perl takes the best features from other languages, such as C, awk, sed, sh, and
BASIC, among others.
 Features:
1. Perls database integration interface DBI supports third-party databases including
Oracle, Sybase, Postgres, MySQL and others.
2. Perl works with HTML, XML, and other mark-up languages.
3. Perl supports Unicode.
4. Perl is Y2K compliant.
5. Perl supports both procedural and object-oriented programming.
6. Perl interfaces with external C/C++ libraries through XS or SWIG.
7. Perl is extensible. There are over 20,000 third party modules available from the
Comprehensive Perl Archive Network (CPAN).
6/15/2016
4
PERL AND THE WEB
 Perl used to be the most popular web programming language due to its text
manipulation capabilities and rapid development cycle.
 Perl is widely known as " the duct-tape of the Internet".
 Perl can handle encrypted Web data, including e-commerce transactions.
 Perl can be embedded into web servers to speed up processing by as much
as 2000%.
 Perl's mod_perl allows the Apache web server to embed a Perl interpreter.
 Perl's DBI package makes web-database integration easy.
6/15/2016
5
PERL IS INTERPRETED
 Perl is an interpreted language, which means that your code can be run as is,
without a compilation stage that creates a non portable executable program.
 Traditional compilers convert programs into machine language. When you
run a Perl program, it's first compiled into a byte code, which is then
converted ( as the program runs) into machine instructions. So it is not quite
the same as shells, or Tcl, which are strictly interpreted without an
intermediate representation.
 It is also not like most versions of C or C++, which are compiled directly
into a machine dependent format.
6/15/2016
6
PERL - ENVIRONMENT SETUP
There is a set up of Perl Programming environment online.
Before we start writing our Perl programs, let's understand how to setup our Perl environment. Perl is
available on a wide variety of platforms −
•Unix
•Win 9x/NT/2000/
•WinCE
•Macintosh (PPC, 68K)
•Solaris (x86, SPARC)
•OpenVMS
•Symbian
•And many more...
This is more likely that your system will have perl installed on it. Just try giving the following command
at the $ prompt −
$perl -v
If you have perl installed on your machine then you will get a message something as follows −
6/15/2016
7
 Getting Perl Installation
 The most up-to-date and current source code, binaries, documentation, news, etc. are available at
the official website of Perl.
 Perl Official Website − http://www.perl.org/
 Install Perl
 Perl distribution is available for a wide variety of platforms. You need to download only the
binary code applicable for your platform and install Perl.
 If the binary code for your platform is not available, you need a C compiler to compile the source
code manually. Compiling the source code offers more flexibility in terms of choice of features
that you require in your installation.
 Here is a quick overview of installing Perl on various platforms.
 1) Unix and Linux Installation
 Here are the simple steps to install Perl on Unix/Linux machine.
 Open a Web browser and go to http://www.perl.org/get.html.
 Follow the link to download zipped source code available for Unix/Linux.
6/15/2016
8
oDownload perl-5.x.y.tar.gz file and issue the following commands at $ prompt.
oNOTE − Here $ is a Unix prompt where you type your command, so make sure you are not typing $
while typing the above mentioned commands.
oThis will install Perl in a standard location
o/usr/local/bin and
oits libraries are installed in /usr/local/lib/perlXX, where XX is the version of Perl that you are using.
oIt will take a while to compile the source code after issuing the make command.
oOnce installation is done, you can issue perl -v command at $ prompt to check perl installation. If
everything is fine, then it will display details of perl .
2) Windows Installation
oHere are the steps to install Perl on Windows machine.
oFollow the link for the Strawberry Perl installation on Windows http://strawberryperl.com
oDownload either 32bit or 64bit version of installation.
oRun the downloaded file by double-clicking it in Windows Explorer. This brings up the Perl install
wizard, which is really easy to use. Just accept the default settings, wait until the installation is finished,
and you're ready to roll!
6/15/2016
9
RUNNING A PERL
 These are the different ways to start Perl.
 (1) Interactive Interpreter
 You can enter perl and start coding right away in the interactive interpreter
by starting it from the command line. You can do this from Unix, DOS, or
any other system, which provides you a command-line interpreter or shell
window.
-e option ------ Runs Perl script sent in as
program
6/15/2016
10
(2) Script from the Command-line
A Perl script is a text file which keeps perl code in it and it can be executed at the
command line by invoking the interpreter on your application, as in the following
(3) Integrated Development Environment
You can run Perl from a graphical user interface (GUI) environment as well. All you need
is a GUI application on your system that supports Perl. You can download Padre, the
Perl IDE. You can also use Eclipse Plugin EPIC - Perl Editor and IDE for Eclipse if
you are familiar with Eclipse.
6/15/2016
11
NAMES IN PERL
 Perl manipulates variables which have a name.
 A value is assigned to/stored in variable by assignment statement of the
form
name=value
 Perl distinguishes between singular name and plural name.
A singular name –holds single item of data– scalar value
A plural name for variable – hold collection of data items —
an array or hash
 Starting special character of variable denotes the kind of thing that name
stands for
 $ ---- Scalar data
 @ ----- Array
 % ----- Hash
 & ----- Sub routine
6/15/2016
12
NAMES IN PERL...
 use strict ‘var’; (or) use strict;
 It tells perl to insist on declaration by placing the line.
 At the start of script variables are declared using
 my $x,$y;
#!/usr/bin/perl
@ages = (25, 30, 40);
@names = ("John Paul", "Lisa", "Kumar");
print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n";
print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n";
print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n";
6/15/2016
13
NAMES IN PERL...
 Valid characters are letters,digits,underscores.
 First character after special character can be a letter or underscore.
 Names may also have non-alphanumeric character after special character.
$$,$? (system reserved names in Perl )
 Each kind of data has separate namespace.
 Special character determine the context in which the name is being used.
 In C language a new variable is declared as
int i=1;
float data[9];
 Scope of variable depends on the part of program in which the variable is visible and
available for use.
 Global scope and local scope.
 Variable declaration in perl –
$a=5;
my $a=10;
 A variable comes into existence when declared or first used with special value denoted by
undef
undef $x;
6/15/2016
14
PERL NAMES,VALUES AND
VARIABLES
BY
SANA MATEEN
6/18/2016
15
NAMES IN PERL
 Perl manipulates variables which have a name.
 A value is assigned to/stored in variable by assignment statement of the
form
name=value
 Perl distinguishes between singular name and plural name.
A singular name –holds single item of data– scalar value
A plural name for variable – hold collection of data items —
an array or hash
 Starting special character of variable denotes the kind of thing that
name stands for
 $ ---- Scalar data
 @ ----- Array
 % ----- Hash
 & ----- Sub routine
6/18/2016
16
NAMES IN PERL...
 Valid characters are letters,digits,underscores.
 First character after special character can be a letter or underscore.
 Names may also have non-alphanumeric character after special character.
$$,$? (system reserved names in Perl )
 Each kind of data has separate namespace.
 Special character determine the context in which the name is being used.
 In C language a new variable is declared as
int i=1;
float data[9];
 Scope of variable depends on the part of program in which the variable is visible and
available for use.
 Global scope and local scope.
 Variable declaration in perl –
$a=5;
my $a=10;
 A variable comes into existence when declared or first used with special value denoted by
undef
undef $x;
6/18/2016
17
NAMES IN PERL...
 use strict ‘var’; (or) use strict;
 It tells perl to insist on declaration by placing the line.
 At the start of script variables are declared using
 my $x,$y;
#!/usr/bin/perl
@ages = (25, 30, 40);
@names = ("John Paul", "Lisa", "Kumar");
print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n";
print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n";
print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n";
6/18/2016
18
A scalar is a single unit of data. Perl recognizes two kinds of scalar data , a String
and Numbers . There’s no difference between integers and real numbers both are
same.
Here is a simple example of using scalar variables −
#!/usr/bin/perl
$age = 25; # An integer assignment
$name = "John Paul"; # A string
$salary = 1445.50; # A floating point
print "Age = $agen";
print "Name = $namen";
print "Salary = $salaryn";
This will produce the following result −
Age = 25 Name = John Paul Salary = 1445.5
Strings are stored as sequence of bytes of unlimited length . Perl is dynamically typed
language (System keeps track of whether a variable contains a numeric value or string
value).Depending on the context strings are converted to int.
Eg:
If int/num occurs in String context, operand for string operator , perl will convert it to
string
Numeric Scalars
A scalar is most often either a number or a string. Following example demonstrates the
usage of various types of numeric scalars −
6/18/2016
19
#!/usr/bin/perl
$integer = 200;
$negative = -300;
$floating = 200.340;
$bigfloat = -1.2E-23;
# 377 octal, same as 255 decimal
$octal = 0377;
# FF hex, also 255 decimal
$hexa = 0xff;
print "integer = $integern";
print "negative = $negativen";
print "floating = $floatingn";
print "bigfloat = $bigfloatn";
print "octal = $octaln";
print "hexa = $hexan";
This will produce the following result −
integer = 200 negative = -300 floating = 200.34 bigfloat = -1.2e-23 octal = 255 hexa =
String Scalars
Following example demonstrates the usage of various types of string scalars.
Notice the difference between single quoted strings and double quoted strings −
#!/usr/bin/perl
$var = "This is string scalar!";
$quote = 'I m inside single quote - $var';
$double = "This is inside single quote - $var";
$escape = "This example of escape -tHello, World!";
print "var = $varn";
print "quote = $quoten";
print "double = $doublen";
print "escape = $escapen";
6/18/2016
20
STRING CONSTANTS/LITERALS
 String constant and literals can be enclosed in single or double quotes.
 The string is terminated by first next occurrence of quote which started it , so single
quoted strings can include double quotes and vice versa.
 Single quoted strings are treated as it is-
‘Fridayn’
 ‘Friday’--- String
 ‘Fridayn’---String with seven characters including last character which is a new
line.
 n-newline,t-tab,U-uppercase
 There is more than one way to choose your own quote
 1.quote — q
 2.double quote– qq
 q /any string/
 or q(any string) and qq(any string), qq /any string/
6/18/2016
21
VARIABLES AND ASSIGNMENT
 Perl uses – ‘=‘ as the assignment operator. It returns a value. This permits
statement like
 $b=4+($a=3);
 $a=“Burger”;
 $b=“Sandwich $a” //$b would give “Sandwich Burger”
 $c=“turkey $a”;
 Scalar variable names start with--$
 $a=“java”;
 $b=“${a} script”;//value is javascript
6/18/2016
22
<STDIN>
 <STDIN>is used for acquiring input from keyboard.If no input is queued
perl will wait until a line is typed and the return key pressed.
 End-of-file
ctrl - D  Unix
ctrl - Z  DOS
 They cause the return to be undefined, it evaluates to “ “ .
 The empty string is treated as false in boolean context.
while(<STDIN>){
.....
}
To process all statements until the end of file is reached.
While(defined <STDIN>){
...
}
6/18/2016
23
BY
SANA MATEEN
SCALAR EXPRESSIONS AND
CONTROL STRUCTURES

More Related Content

What's hot (20)

PPTX
Phylogenetic data analysis
Md. Dilshad karim
 
PPTX
Swiss pdb viewer
Sivasangari Shanmugam
 
PPT
Clustal
Benittabenny
 
PDF
PERL- Bioperl modules
Nixon Mendez
 
PPTX
codon_optimization
HARSHITHA EBBALI
 
PPTX
Protein Databases
SATHIYA NARAYANAN
 
PPTX
Sequence Alignment
Meghaj Mallick
 
PPTX
sequence of file formats in bioinformatics
nadeem akhter
 
PPTX
Sequence alignment global vs. local
benazeer fathima
 
PPT
swiss-prot<bioinformatics>
Pardeep kaushal
 
PPTX
Protein protein interactions
SHRIKANT YANKANCHI
 
PPT
Sequence file formats
Alphonsa Joseph
 
PDF
Protein Structure Prediction
Balachandramohan Bcm
 
PPTX
Comparative genomics
hemantbreeder
 
PDF
Phylogenetic analysis
Nitin Naik
 
PPT
Secondary structure prediction
samantlalit
 
PPT
The uni prot knowledgebase
Kew Sama
 
PPTX
Protein databases
sarumalay
 
Phylogenetic data analysis
Md. Dilshad karim
 
Swiss pdb viewer
Sivasangari Shanmugam
 
Clustal
Benittabenny
 
PERL- Bioperl modules
Nixon Mendez
 
codon_optimization
HARSHITHA EBBALI
 
Protein Databases
SATHIYA NARAYANAN
 
Sequence Alignment
Meghaj Mallick
 
sequence of file formats in bioinformatics
nadeem akhter
 
Sequence alignment global vs. local
benazeer fathima
 
swiss-prot<bioinformatics>
Pardeep kaushal
 
Protein protein interactions
SHRIKANT YANKANCHI
 
Sequence file formats
Alphonsa Joseph
 
Protein Structure Prediction
Balachandramohan Bcm
 
Comparative genomics
hemantbreeder
 
Phylogenetic analysis
Nitin Naik
 
Secondary structure prediction
samantlalit
 
The uni prot knowledgebase
Kew Sama
 
Protein databases
sarumalay
 

Viewers also liked (9)

PPTX
Unit 1-strings,patterns and regular expressions
sana mateen
 
PPTX
Unit 1-perl names values and variables
sana mateen
 
PPTX
Unit 1-subroutines in perl
sana mateen
 
PPTX
Unit 1-scalar expressions and control structures
sana mateen
 
PPTX
Unit 1-uses for scripting languages,web scripting
sana mateen
 
PPTX
Unit 1-array,lists and hashes
sana mateen
 
PPTX
Unit 1-introduction to scripts
sana mateen
 
ODP
Introduction to Perl - Day 1
Dave Cross
 
PPT
PPT - Powerful Presentation Techniques
University of Wisconsin Milwaukee
 
Unit 1-strings,patterns and regular expressions
sana mateen
 
Unit 1-perl names values and variables
sana mateen
 
Unit 1-subroutines in perl
sana mateen
 
Unit 1-scalar expressions and control structures
sana mateen
 
Unit 1-uses for scripting languages,web scripting
sana mateen
 
Unit 1-array,lists and hashes
sana mateen
 
Unit 1-introduction to scripts
sana mateen
 
Introduction to Perl - Day 1
Dave Cross
 
PPT - Powerful Presentation Techniques
University of Wisconsin Milwaukee
 
Ad

Similar to Unit 1-introduction to perl (20)

PPTX
Introduction to perl
sana mateen
 
PPT
Perl Reference.ppt
AshleshaKulkarni4
 
PDF
Introduction to PERL Programming - Complete Notes
Jason J Pulikkottil
 
PPT
Introduction to perl scripting______.ppt
nalinisamineni
 
PPT
PERL - complete_Training_Modules_Ref.ppt
ssuserf4000e1
 
PPT
PERL - complete_guide_references (1).ppt
ssuserf4000e1
 
PPT
Perl Basics with Examples
Nithin Kumar Singani
 
PDF
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
PPTX
programming language interface i.pptx
urvashipundir04
 
ODP
Add Perl to Your Toolbelt
daoswald
 
PPTX
Intro to Perl
primeteacher32
 
PPTX
Webinar: Learn Perl - The Jewel of Scripting Languages
Edureka!
 
PDF
Perl tutorial
HarikaReddy115
 
PDF
perltut
tutorialsruby
 
PDF
perltut
tutorialsruby
 
PPTX
perl lauange
Naga Dinesh
 
PPTX
Pearl
Naga Dinesh
 
PPT
Introduction to perl_ a scripting language
Vamshi Santhapuri
 
PDF
perl
tutorialsruby
 
Introduction to perl
sana mateen
 
Perl Reference.ppt
AshleshaKulkarni4
 
Introduction to PERL Programming - Complete Notes
Jason J Pulikkottil
 
Introduction to perl scripting______.ppt
nalinisamineni
 
PERL - complete_Training_Modules_Ref.ppt
ssuserf4000e1
 
PERL - complete_guide_references (1).ppt
ssuserf4000e1
 
Perl Basics with Examples
Nithin Kumar Singani
 
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
programming language interface i.pptx
urvashipundir04
 
Add Perl to Your Toolbelt
daoswald
 
Intro to Perl
primeteacher32
 
Webinar: Learn Perl - The Jewel of Scripting Languages
Edureka!
 
Perl tutorial
HarikaReddy115
 
perltut
tutorialsruby
 
perltut
tutorialsruby
 
perl lauange
Naga Dinesh
 
Introduction to perl_ a scripting language
Vamshi Santhapuri
 
Ad

More from sana mateen (20)

PPTX
Files
sana mateen
 
PPTX
PHP Variables and scopes
sana mateen
 
PPTX
Php intro
sana mateen
 
PPTX
Php and web forms
sana mateen
 
PPTX
Mail
sana mateen
 
PPTX
Files in php
sana mateen
 
PPTX
File upload php
sana mateen
 
PPTX
Regex posix
sana mateen
 
PPTX
Encryption in php
sana mateen
 
PPTX
Authentication methods
sana mateen
 
PPTX
Xml schema
sana mateen
 
PPTX
Xml dtd
sana mateen
 
PPTX
Xml dom
sana mateen
 
PPTX
Xhtml
sana mateen
 
PPTX
Intro xml
sana mateen
 
PPTX
Dom parser
sana mateen
 
PPTX
Uses for scripting languages,web scripting in perl
sana mateen
 
PPTX
Scalar expressions and control structures in perl
sana mateen
 
PPTX
Subroutines in perl
sana mateen
 
PPTX
Strings,patterns and regular expressions in perl
sana mateen
 
PHP Variables and scopes
sana mateen
 
Php intro
sana mateen
 
Php and web forms
sana mateen
 
Files in php
sana mateen
 
File upload php
sana mateen
 
Regex posix
sana mateen
 
Encryption in php
sana mateen
 
Authentication methods
sana mateen
 
Xml schema
sana mateen
 
Xml dtd
sana mateen
 
Xml dom
sana mateen
 
Intro xml
sana mateen
 
Dom parser
sana mateen
 
Uses for scripting languages,web scripting in perl
sana mateen
 
Scalar expressions and control structures in perl
sana mateen
 
Subroutines in perl
sana mateen
 
Strings,patterns and regular expressions in perl
sana mateen
 

Recently uploaded (20)

PPTX
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
smart lot access control system with eye
rasabzahra
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
smart lot access control system with eye
rasabzahra
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Zilliz Cloud Demo for performance and scale
Zilliz
 

Unit 1-introduction to perl

  • 1. CHARACTERISTICS OF SCRIPTING LANGUAGE  Efficiency is not an issue Ease of use is achieved at the expense of efficiency eg: interpretation rather than compiling Focus is not on high performance but on the speed of development together with ability to make changes to meet new requirement. 6/13/2016 1Introduction to scripts and scripting
  • 2. INTRODUCTION TO PERL By Sana Mateen 6/15/2016 2
  • 3. PERL—PRACTICAL EXTRACTION REPORT LANGUAGE  Perl is a programming language developed by Larry Wall, especially designed for text processing. Though Perl is not officially an acronym but many times it is used as it stands for Practical Extraction and Report Language. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.  Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development(wxperl and perl-tk interfaces), and more. 6/15/2016 3
  • 4. WHAT IS PERL? AND PERL FEATURES ? 1. Perl is a stable, cross platform programming language. 2. Though Perl is not officially an acronym but few people used it as Practical Extraction and Report Language. 3. It is used for mission critical projects in the public and private sectors. 4. Perl is an Open Source software, licensed under its Artistic License, or the GNU General Public License (GPL). 5. Perl takes the best features from other languages, such as C, awk, sed, sh, and BASIC, among others.  Features: 1. Perls database integration interface DBI supports third-party databases including Oracle, Sybase, Postgres, MySQL and others. 2. Perl works with HTML, XML, and other mark-up languages. 3. Perl supports Unicode. 4. Perl is Y2K compliant. 5. Perl supports both procedural and object-oriented programming. 6. Perl interfaces with external C/C++ libraries through XS or SWIG. 7. Perl is extensible. There are over 20,000 third party modules available from the Comprehensive Perl Archive Network (CPAN). 6/15/2016 4
  • 5. PERL AND THE WEB  Perl used to be the most popular web programming language due to its text manipulation capabilities and rapid development cycle.  Perl is widely known as " the duct-tape of the Internet".  Perl can handle encrypted Web data, including e-commerce transactions.  Perl can be embedded into web servers to speed up processing by as much as 2000%.  Perl's mod_perl allows the Apache web server to embed a Perl interpreter.  Perl's DBI package makes web-database integration easy. 6/15/2016 5
  • 6. PERL IS INTERPRETED  Perl is an interpreted language, which means that your code can be run as is, without a compilation stage that creates a non portable executable program.  Traditional compilers convert programs into machine language. When you run a Perl program, it's first compiled into a byte code, which is then converted ( as the program runs) into machine instructions. So it is not quite the same as shells, or Tcl, which are strictly interpreted without an intermediate representation.  It is also not like most versions of C or C++, which are compiled directly into a machine dependent format. 6/15/2016 6
  • 7. PERL - ENVIRONMENT SETUP There is a set up of Perl Programming environment online. Before we start writing our Perl programs, let's understand how to setup our Perl environment. Perl is available on a wide variety of platforms − •Unix •Win 9x/NT/2000/ •WinCE •Macintosh (PPC, 68K) •Solaris (x86, SPARC) •OpenVMS •Symbian •And many more... This is more likely that your system will have perl installed on it. Just try giving the following command at the $ prompt − $perl -v If you have perl installed on your machine then you will get a message something as follows − 6/15/2016 7
  • 8.  Getting Perl Installation  The most up-to-date and current source code, binaries, documentation, news, etc. are available at the official website of Perl.  Perl Official Website − http://www.perl.org/  Install Perl  Perl distribution is available for a wide variety of platforms. You need to download only the binary code applicable for your platform and install Perl.  If the binary code for your platform is not available, you need a C compiler to compile the source code manually. Compiling the source code offers more flexibility in terms of choice of features that you require in your installation.  Here is a quick overview of installing Perl on various platforms.  1) Unix and Linux Installation  Here are the simple steps to install Perl on Unix/Linux machine.  Open a Web browser and go to http://www.perl.org/get.html.  Follow the link to download zipped source code available for Unix/Linux. 6/15/2016 8
  • 9. oDownload perl-5.x.y.tar.gz file and issue the following commands at $ prompt. oNOTE − Here $ is a Unix prompt where you type your command, so make sure you are not typing $ while typing the above mentioned commands. oThis will install Perl in a standard location o/usr/local/bin and oits libraries are installed in /usr/local/lib/perlXX, where XX is the version of Perl that you are using. oIt will take a while to compile the source code after issuing the make command. oOnce installation is done, you can issue perl -v command at $ prompt to check perl installation. If everything is fine, then it will display details of perl . 2) Windows Installation oHere are the steps to install Perl on Windows machine. oFollow the link for the Strawberry Perl installation on Windows http://strawberryperl.com oDownload either 32bit or 64bit version of installation. oRun the downloaded file by double-clicking it in Windows Explorer. This brings up the Perl install wizard, which is really easy to use. Just accept the default settings, wait until the installation is finished, and you're ready to roll! 6/15/2016 9
  • 10. RUNNING A PERL  These are the different ways to start Perl.  (1) Interactive Interpreter  You can enter perl and start coding right away in the interactive interpreter by starting it from the command line. You can do this from Unix, DOS, or any other system, which provides you a command-line interpreter or shell window. -e option ------ Runs Perl script sent in as program 6/15/2016 10
  • 11. (2) Script from the Command-line A Perl script is a text file which keeps perl code in it and it can be executed at the command line by invoking the interpreter on your application, as in the following (3) Integrated Development Environment You can run Perl from a graphical user interface (GUI) environment as well. All you need is a GUI application on your system that supports Perl. You can download Padre, the Perl IDE. You can also use Eclipse Plugin EPIC - Perl Editor and IDE for Eclipse if you are familiar with Eclipse. 6/15/2016 11
  • 12. NAMES IN PERL  Perl manipulates variables which have a name.  A value is assigned to/stored in variable by assignment statement of the form name=value  Perl distinguishes between singular name and plural name. A singular name –holds single item of data– scalar value A plural name for variable – hold collection of data items — an array or hash  Starting special character of variable denotes the kind of thing that name stands for  $ ---- Scalar data  @ ----- Array  % ----- Hash  & ----- Sub routine 6/15/2016 12
  • 13. NAMES IN PERL...  use strict ‘var’; (or) use strict;  It tells perl to insist on declaration by placing the line.  At the start of script variables are declared using  my $x,$y; #!/usr/bin/perl @ages = (25, 30, 40); @names = ("John Paul", "Lisa", "Kumar"); print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n"; print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n"; print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n"; 6/15/2016 13
  • 14. NAMES IN PERL...  Valid characters are letters,digits,underscores.  First character after special character can be a letter or underscore.  Names may also have non-alphanumeric character after special character. $$,$? (system reserved names in Perl )  Each kind of data has separate namespace.  Special character determine the context in which the name is being used.  In C language a new variable is declared as int i=1; float data[9];  Scope of variable depends on the part of program in which the variable is visible and available for use.  Global scope and local scope.  Variable declaration in perl – $a=5; my $a=10;  A variable comes into existence when declared or first used with special value denoted by undef undef $x; 6/15/2016 14
  • 16. NAMES IN PERL  Perl manipulates variables which have a name.  A value is assigned to/stored in variable by assignment statement of the form name=value  Perl distinguishes between singular name and plural name. A singular name –holds single item of data– scalar value A plural name for variable – hold collection of data items — an array or hash  Starting special character of variable denotes the kind of thing that name stands for  $ ---- Scalar data  @ ----- Array  % ----- Hash  & ----- Sub routine 6/18/2016 16
  • 17. NAMES IN PERL...  Valid characters are letters,digits,underscores.  First character after special character can be a letter or underscore.  Names may also have non-alphanumeric character after special character. $$,$? (system reserved names in Perl )  Each kind of data has separate namespace.  Special character determine the context in which the name is being used.  In C language a new variable is declared as int i=1; float data[9];  Scope of variable depends on the part of program in which the variable is visible and available for use.  Global scope and local scope.  Variable declaration in perl – $a=5; my $a=10;  A variable comes into existence when declared or first used with special value denoted by undef undef $x; 6/18/2016 17
  • 18. NAMES IN PERL...  use strict ‘var’; (or) use strict;  It tells perl to insist on declaration by placing the line.  At the start of script variables are declared using  my $x,$y; #!/usr/bin/perl @ages = (25, 30, 40); @names = ("John Paul", "Lisa", "Kumar"); print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n"; print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n"; print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n"; 6/18/2016 18
  • 19. A scalar is a single unit of data. Perl recognizes two kinds of scalar data , a String and Numbers . There’s no difference between integers and real numbers both are same. Here is a simple example of using scalar variables − #!/usr/bin/perl $age = 25; # An integer assignment $name = "John Paul"; # A string $salary = 1445.50; # A floating point print "Age = $agen"; print "Name = $namen"; print "Salary = $salaryn"; This will produce the following result − Age = 25 Name = John Paul Salary = 1445.5 Strings are stored as sequence of bytes of unlimited length . Perl is dynamically typed language (System keeps track of whether a variable contains a numeric value or string value).Depending on the context strings are converted to int. Eg: If int/num occurs in String context, operand for string operator , perl will convert it to string Numeric Scalars A scalar is most often either a number or a string. Following example demonstrates the usage of various types of numeric scalars − 6/18/2016 19
  • 20. #!/usr/bin/perl $integer = 200; $negative = -300; $floating = 200.340; $bigfloat = -1.2E-23; # 377 octal, same as 255 decimal $octal = 0377; # FF hex, also 255 decimal $hexa = 0xff; print "integer = $integern"; print "negative = $negativen"; print "floating = $floatingn"; print "bigfloat = $bigfloatn"; print "octal = $octaln"; print "hexa = $hexan"; This will produce the following result − integer = 200 negative = -300 floating = 200.34 bigfloat = -1.2e-23 octal = 255 hexa = String Scalars Following example demonstrates the usage of various types of string scalars. Notice the difference between single quoted strings and double quoted strings − #!/usr/bin/perl $var = "This is string scalar!"; $quote = 'I m inside single quote - $var'; $double = "This is inside single quote - $var"; $escape = "This example of escape -tHello, World!"; print "var = $varn"; print "quote = $quoten"; print "double = $doublen"; print "escape = $escapen"; 6/18/2016 20
  • 21. STRING CONSTANTS/LITERALS  String constant and literals can be enclosed in single or double quotes.  The string is terminated by first next occurrence of quote which started it , so single quoted strings can include double quotes and vice versa.  Single quoted strings are treated as it is- ‘Fridayn’  ‘Friday’--- String  ‘Fridayn’---String with seven characters including last character which is a new line.  n-newline,t-tab,U-uppercase  There is more than one way to choose your own quote  1.quote — q  2.double quote– qq  q /any string/  or q(any string) and qq(any string), qq /any string/ 6/18/2016 21
  • 22. VARIABLES AND ASSIGNMENT  Perl uses – ‘=‘ as the assignment operator. It returns a value. This permits statement like  $b=4+($a=3);  $a=“Burger”;  $b=“Sandwich $a” //$b would give “Sandwich Burger”  $c=“turkey $a”;  Scalar variable names start with--$  $a=“java”;  $b=“${a} script”;//value is javascript 6/18/2016 22
  • 23. <STDIN>  <STDIN>is used for acquiring input from keyboard.If no input is queued perl will wait until a line is typed and the return key pressed.  End-of-file ctrl - D  Unix ctrl - Z  DOS  They cause the return to be undefined, it evaluates to “ “ .  The empty string is treated as false in boolean context. while(<STDIN>){ ..... } To process all statements until the end of file is reached. While(defined <STDIN>){ ... } 6/18/2016 23
  • 24. BY SANA MATEEN SCALAR EXPRESSIONS AND CONTROL STRUCTURES