SlideShare a Scribd company logo
3
Most read
4
Most read
5
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

PPTX
PPTX
Introduction to sequence alignment partii
PPTX
Bioinformatics p1-perl-introduction v2013
PPT
Perl Basics with Examples
PDF
sequence alignment
PDF
High throughput sequencing
Introduction to sequence alignment partii
Bioinformatics p1-perl-introduction v2013
Perl Basics with Examples
sequence alignment
High throughput sequencing

What's hot (20)

DOCX
Open Reading Frames
PPTX
Whole genome shotgun sequencing
PPTX
Sequence alignment
PPTX
Sequenced taged sites (sts)
PDF
Sequence alignment
PDF
Perl Scripting
PPT
Phylogenetic prediction - maximum parsimony method
PDF
Introduction to Perl and BioPerl
PPTX
Comparative genomics
PPTX
Gene prediction and expression
DOCX
UniProt
PDF
Gene prediction method
PPTX
Sequence Assembly
PPTX
Algorithm research project neighbor joining
PPTX
YEAST TWO HYBRID SYSTEM
PPTX
GENOME ORGANISATION IN EUKARYOTES
DOCX
Data retrieval tools
PPTX
Gen bank databases
PDF
Genome Assembly
Open Reading Frames
Whole genome shotgun sequencing
Sequence alignment
Sequenced taged sites (sts)
Sequence alignment
Perl Scripting
Phylogenetic prediction - maximum parsimony method
Introduction to Perl and BioPerl
Comparative genomics
Gene prediction and expression
UniProt
Gene prediction method
Sequence Assembly
Algorithm research project neighbor joining
YEAST TWO HYBRID SYSTEM
GENOME ORGANISATION IN EUKARYOTES
Data retrieval tools
Gen bank databases
Genome Assembly
Ad

Viewers also liked (9)

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

Similar to Unit 1-introduction to perl (20)

PPTX
Introduction to perl
PPTX
PPTX
perl lauange
PPT
Introduction to perl_ a scripting language
PPTX
programming language interface i.pptx
PPT
Perl Reference.ppt
PPTX
PPT
PERL - complete_guide_references (1).ppt
PPT
PERL - complete_Training_Modules_Ref.ppt
PDF
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
PPT
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
PDF
Introduction to PERL Programming - Complete Notes
PPT
Bioinformatica 29-09-2011-p1-introduction
PDF
Enterprise Perl
DOCX
Perl 20tips
PDF
Perl_Part1
PDF
Introduction to writing readable and maintainable Perl
PPTX
Group1_PERL.pptx
PPTX
Future of PERL in IT
Introduction to perl
perl lauange
Introduction to perl_ a scripting language
programming language interface i.pptx
Perl Reference.ppt
PERL - complete_guide_references (1).ppt
PERL - complete_Training_Modules_Ref.ppt
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Introduction to PERL Programming - Complete Notes
Bioinformatica 29-09-2011-p1-introduction
Enterprise Perl
Perl 20tips
Perl_Part1
Introduction to writing readable and maintainable Perl
Group1_PERL.pptx
Future of PERL in IT

More from sana mateen (20)

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

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
Sustainable Sites - Green Building Construction
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Well-logging-methods_new................
PPTX
web development for engineering and engineering
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
PPT on Performance Review to get promotions
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Lecture Notes Electrical Wiring System Components
Automation-in-Manufacturing-Chapter-Introduction.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Internet of Things (IOT) - A guide to understanding
CYBER-CRIMES AND SECURITY A guide to understanding
Digital Logic Computer Design lecture notes
Sustainable Sites - Green Building Construction
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
OOP with Java - Java Introduction (Basics)
Well-logging-methods_new................
web development for engineering and engineering
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT on Performance Review to get promotions
Model Code of Practice - Construction Work - 21102022 .pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Embodied AI: Ushering in the Next Era of Intelligent Systems
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx

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