SlideShare a Scribd company logo
1 of 24
Vamshi Krishna S
Practical Extraction and Report Language
‘A general-purpose programming language originally developed for text
manipulation and now used for a wide range of tasks including system
administration, web development-CGI scripting, network programming, GUI
development, and more.’
‘The language is intended to be PRACTICAL (easy to use, efficient, complete) rather than
BEAUTIFUL (tiny, elegant, minimal).’
And Some More:
‘Many earlier computer languages, such as Fortran and C, were designed to make
efficient use of expensive
computer hardware. In contrast, Perl is designed to make efficient use of
expensive computer programmers.
Perl has many features that ease the programmer's task at the expense of greater
CPU and memory requirements.
These include automatic memory management; dynamic typing; strings, lists, and
hashes; regular expressions;
 Larry Wall invented PERL in the mid-1980's
Larry Wall was trained as a linguist, and the design of Perl is very much
informed by linguistic principles.
Examples include Huffman coding (common constructions should be
short), good end-weighting (the important information should
come first), and a large collection of language primitives. Perl favors
language constructs that are natural for humans to
read and write, even where they complicate the Perl interpreter.’
Perl has rapidly become the language of choice for writing programs
quickly and robustly across a wide range of fields - ranging from
systems administration, text processing, linguistic analysis, molecular
biology and (most importantly of all) the creation of dynamic World
Wide Web pages. It has been estimated that about 80% of dynamic
webpages worldwide are being created by Perl programs.
 PERL encompasses both the syntactical rules of the
language and the general ways in which programs are
organized
 It is dynamically typed language.
 Relatively easy to learn (and easier to make a mess
too).
 incredibly flexible coding style (some argues it is too
flexible).
 Perl is interpreted not complied hence its scripting
language.
 It follows OOPs concepts.
 http://perldoc.perl.org/perldoc.html
 CPAN(comprehensive Pern Archive
Network) : consists of Additional perl
modules(more than 100,000 modules),
documentation,various releases etc.,
 HTTP://cpan.org/
 Define the problem
 Search for existing code
 Plan your solution
 Write the code
 Modify ->Debug ->Modify
 Run the code
 Now-a-days On *nix
OSes Perl comes
installed
automatically. And
can be located at
/usr/bin/perl and /
usr/local/bin/perl
To install Perl on
Windows :
 http://strawberry
perl.com/
 http://www.activ
estate.com/active
perl
 Open a terminal
 Make a perl dir(directory) in your home dir
 Move into the perl directory
 Create a file named ‘hello_world.pl’
 Open the file in your text editor
 Code the program
 Save the file
 Make the program executable
 Test the program.
 # Unix
 perl -e 'print "Hello worldn"‘
 # MS-DOS
 perl -e "print "Hello worldn""
Location of perl is normally in
/usr/bin/perl and /usr/local/bin/perl
Perfix the script with #!/usr/bin/perl
And also you can type in “use <version>” to use the
latest version
#!/usr/bin/perl -w
use strict;
use warnings;
my $message = ‘Welcome to perl tutorial’;
print “t hello world $message.!!n”;
print ‘hello world $message.!!n’
#prints $messagen literally
 Scalar: a single piece of information. Scalars can
hold numbers or text
 $ is the identifier of scalar in perl
 There are special variables for the system: $ARGV,$!
 @scores = (32, 45, 16, 5);
 @cars = (BMW,Renault,Jaguar,Ferrari); or @cars =
qw(BMW Renault Jaguar Ferrari);
 my @sorted = sort @cars;
 my @backwards = reverse @scores;
 $multilined_string = <<EOF; This is my multilined string note that I am
terminating it with the word "EOF". EOF
 Scalar values are represented as $var = <num/char> ; Dynamic typing
 Array/List: an ordered collection of scalars
 my @array = ( 1, 2 );
 my @words = ( "first", "second", "third" );
 my @mixed = ("camel", 42, 1.23);
print $mixed[$#mixed]; # last element, prints out
1.23
 Subscripts
An array can be accessed one scalar at a time by specifying a
dollar sign ($ ), then the name of the array (without the
leading @ ), then the subscript inside square brackets.
 For example:
@myarray = (5, 50, 500, 5000);
print "The Third Element is", $myarray[2], "n";
Declaration of HASHes
%scientists =
(
"Newton" => "Isaac",
"Einstein" => "Albert",
"Darwin" => "Charles",
"Feynman" => "Richard",
);
print "Darwin's First Name is ", $scientists{"Darwin"}, "n";
Hash subscripts are similar, only instead of square brackets curly brackets
are used
my %fruit_color = ("apple", "red", "banana", "yellow");
 To get at hash elements:
$fruit_color{"apple"}; # gives "red“
 To get a lists of keys and values with keys() and values().
my @fruits = keys %fruit_colors;
my @colors = values %fruit_colors;
 Some scalar variables have special meaning
in Perl. Of note are `$_`,
`$!`, `$0`, and `$$`.
 There are system defined functions for
operations on Scalar variables, Arrays,
Hashes, File Handlers, Regular Expressions,
Sub routines, Modules etc., which appear like
keywords some times and take arguments
Eg: Chomp, join, my, our, grep, mkdir, open,
import,defined,undef,sort,reverse etc.,
For detailed description follow: http://perldoc.perl.org/perlfunc.html#Perl-Functions-by-Category
 double quotes(“), single quotes(‘) and
multi-line quoting(qq) :
$var =10;
$text = “There are $var apples”
$text2 = ‘There are $var apples’
$text3 = qq{
There
are
$var
apples};
Functions are blocks of code which perform specific task
#takes no input and returns no output… common practice to use
#‘main’ as the starting point in a script.
sub main {
…
}
#Takes 2 *scalars* as input sums them and returns one scalar.
sub sum_2_numbers {
my ($numA,$numB) = @_; #get passed in values
my $sum = $numA+$numB; #sum numbers
return($sum); #return sum
}
 if/else
 if ( condition ) {…} elsif ( other condition ) {…} else {…}
 Unless
die "Can't cd to spool: $!n" unless chdir '/usr/spool/news';
 While
while (($key, $value) = each %hash) {
print $key, "n";
delete $hash{$key};
}
 Until
$count = 10; until ($count == 0) { print "$count "; $count--;}
 foreach
foreach $index (0 .. $#ARRAY) {
delete $ARRAY[$index];
 Logical operators: ==, !=, &&, ||, eq and ne
 Undefined/” ”/0 values are treated as
false
 Scalars are evaluated as:
numbers are evaluated as true if non-zero
strings are evaluated as true if non-empty
$var = “false”;
if($var)
{
say “$var is true!”;
}
 Scripts can take inputs in two ways:
 Arguments
 ./print_args.pl ARG1 ARG2
 Prompted inputs from users
 $user_text = <STDIN>
 Things don’t always come out as expected. It
is good to check the output of important
functions for errors, it is highly
recommended to validate any input from
users or external sources
 Die
 Warn
Introduction to perl_ a scripting language

More Related Content

What's hot (20)

Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Pearl
PearlPearl
Pearl
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Php basics
Php basicsPhp basics
Php basics
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
 

Viewers also liked

Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perlworr1244
 
POD2::* and Perl translation documentation project
POD2::* and Perl translation documentation projectPOD2::* and Perl translation documentation project
POD2::* and Perl translation documentation projectEnrico Sorcinelli
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl ProgrammingUtkarsh Sengar
 
Perl programming language
Perl programming languagePerl programming language
Perl programming languageElie Obeid
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!Ricardo Signes
 

Viewers also liked (11)

Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 
Perl intro
Perl introPerl intro
Perl intro
 
POD2::* and Perl translation documentation project
POD2::* and Perl translation documentation projectPOD2::* and Perl translation documentation project
POD2::* and Perl translation documentation project
 
perl-java
perl-javaperl-java
perl-java
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
 
pickingUpPerl
pickingUpPerlpickingUpPerl
pickingUpPerl
 
Perl
PerlPerl
Perl
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 

Similar to Introduction to perl_ a scripting language

Similar to Introduction to perl_ a scripting language (20)

Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
Introduction to Perl Programming
Introduction to Perl ProgrammingIntroduction to Perl Programming
Introduction to Perl Programming
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Perl tutorial final
Perl tutorial finalPerl tutorial final
Perl tutorial final
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to writing readable and maintainable Perl
Introduction to writing readable and maintainable PerlIntroduction to writing readable and maintainable Perl
Introduction to writing readable and maintainable Perl
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Introduction to perl_ a scripting language

  • 2. Practical Extraction and Report Language ‘A general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development-CGI scripting, network programming, GUI development, and more.’ ‘The language is intended to be PRACTICAL (easy to use, efficient, complete) rather than BEAUTIFUL (tiny, elegant, minimal).’ And Some More: ‘Many earlier computer languages, such as Fortran and C, were designed to make efficient use of expensive computer hardware. In contrast, Perl is designed to make efficient use of expensive computer programmers. Perl has many features that ease the programmer's task at the expense of greater CPU and memory requirements. These include automatic memory management; dynamic typing; strings, lists, and hashes; regular expressions;
  • 3.  Larry Wall invented PERL in the mid-1980's Larry Wall was trained as a linguist, and the design of Perl is very much informed by linguistic principles. Examples include Huffman coding (common constructions should be short), good end-weighting (the important information should come first), and a large collection of language primitives. Perl favors language constructs that are natural for humans to read and write, even where they complicate the Perl interpreter.’ Perl has rapidly become the language of choice for writing programs quickly and robustly across a wide range of fields - ranging from systems administration, text processing, linguistic analysis, molecular biology and (most importantly of all) the creation of dynamic World Wide Web pages. It has been estimated that about 80% of dynamic webpages worldwide are being created by Perl programs.
  • 4.  PERL encompasses both the syntactical rules of the language and the general ways in which programs are organized  It is dynamically typed language.  Relatively easy to learn (and easier to make a mess too).  incredibly flexible coding style (some argues it is too flexible).  Perl is interpreted not complied hence its scripting language.  It follows OOPs concepts.  http://perldoc.perl.org/perldoc.html
  • 5.  CPAN(comprehensive Pern Archive Network) : consists of Additional perl modules(more than 100,000 modules), documentation,various releases etc.,  HTTP://cpan.org/
  • 6.  Define the problem  Search for existing code  Plan your solution  Write the code  Modify ->Debug ->Modify  Run the code
  • 7.  Now-a-days On *nix OSes Perl comes installed automatically. And can be located at /usr/bin/perl and / usr/local/bin/perl To install Perl on Windows :  http://strawberry perl.com/  http://www.activ estate.com/active perl
  • 8.  Open a terminal  Make a perl dir(directory) in your home dir  Move into the perl directory  Create a file named ‘hello_world.pl’  Open the file in your text editor  Code the program  Save the file  Make the program executable  Test the program.
  • 9.  # Unix  perl -e 'print "Hello worldn"‘  # MS-DOS  perl -e "print "Hello worldn""
  • 10. Location of perl is normally in /usr/bin/perl and /usr/local/bin/perl Perfix the script with #!/usr/bin/perl And also you can type in “use <version>” to use the latest version #!/usr/bin/perl -w use strict; use warnings; my $message = ‘Welcome to perl tutorial’; print “t hello world $message.!!n”; print ‘hello world $message.!!n’ #prints $messagen literally
  • 11.  Scalar: a single piece of information. Scalars can hold numbers or text  $ is the identifier of scalar in perl  There are special variables for the system: $ARGV,$!  @scores = (32, 45, 16, 5);  @cars = (BMW,Renault,Jaguar,Ferrari); or @cars = qw(BMW Renault Jaguar Ferrari);  my @sorted = sort @cars;  my @backwards = reverse @scores;  $multilined_string = <<EOF; This is my multilined string note that I am terminating it with the word "EOF". EOF  Scalar values are represented as $var = <num/char> ; Dynamic typing
  • 12.  Array/List: an ordered collection of scalars  my @array = ( 1, 2 );  my @words = ( "first", "second", "third" );  my @mixed = ("camel", 42, 1.23); print $mixed[$#mixed]; # last element, prints out 1.23  Subscripts An array can be accessed one scalar at a time by specifying a dollar sign ($ ), then the name of the array (without the leading @ ), then the subscript inside square brackets.  For example: @myarray = (5, 50, 500, 5000); print "The Third Element is", $myarray[2], "n";
  • 13. Declaration of HASHes %scientists = ( "Newton" => "Isaac", "Einstein" => "Albert", "Darwin" => "Charles", "Feynman" => "Richard", ); print "Darwin's First Name is ", $scientists{"Darwin"}, "n"; Hash subscripts are similar, only instead of square brackets curly brackets are used
  • 14. my %fruit_color = ("apple", "red", "banana", "yellow");  To get at hash elements: $fruit_color{"apple"}; # gives "red“  To get a lists of keys and values with keys() and values(). my @fruits = keys %fruit_colors; my @colors = values %fruit_colors;
  • 15.  Some scalar variables have special meaning in Perl. Of note are `$_`, `$!`, `$0`, and `$$`.
  • 16.  There are system defined functions for operations on Scalar variables, Arrays, Hashes, File Handlers, Regular Expressions, Sub routines, Modules etc., which appear like keywords some times and take arguments Eg: Chomp, join, my, our, grep, mkdir, open, import,defined,undef,sort,reverse etc., For detailed description follow: http://perldoc.perl.org/perlfunc.html#Perl-Functions-by-Category
  • 17.  double quotes(“), single quotes(‘) and multi-line quoting(qq) : $var =10; $text = “There are $var apples” $text2 = ‘There are $var apples’ $text3 = qq{ There are $var apples};
  • 18. Functions are blocks of code which perform specific task #takes no input and returns no output… common practice to use #‘main’ as the starting point in a script. sub main { … } #Takes 2 *scalars* as input sums them and returns one scalar. sub sum_2_numbers { my ($numA,$numB) = @_; #get passed in values my $sum = $numA+$numB; #sum numbers return($sum); #return sum }
  • 19.  if/else  if ( condition ) {…} elsif ( other condition ) {…} else {…}  Unless die "Can't cd to spool: $!n" unless chdir '/usr/spool/news';  While while (($key, $value) = each %hash) { print $key, "n"; delete $hash{$key}; }  Until $count = 10; until ($count == 0) { print "$count "; $count--;}  foreach foreach $index (0 .. $#ARRAY) { delete $ARRAY[$index];
  • 20.  Logical operators: ==, !=, &&, ||, eq and ne
  • 21.  Undefined/” ”/0 values are treated as false  Scalars are evaluated as: numbers are evaluated as true if non-zero strings are evaluated as true if non-empty $var = “false”; if($var) { say “$var is true!”; }
  • 22.  Scripts can take inputs in two ways:  Arguments  ./print_args.pl ARG1 ARG2  Prompted inputs from users  $user_text = <STDIN>
  • 23.  Things don’t always come out as expected. It is good to check the output of important functions for errors, it is highly recommended to validate any input from users or external sources  Die  Warn

Editor's Notes

  1. Get unix/programming background Purpose of the course is more a introduction to perl, a quick tour rather than a programming course.
  2. Dynamic typing