尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Perl Tutorial
Why PERL ???
♦ Practical extraction and report language
♦ Similar to shell script but lot easier and more
powerful
♦ Easy availablity
♦ All details available on web
Why PERL ???
♦ Perl stands for practical
extraction and report language.
♦ Perl is similar to shell script.
Only it is much easier and more
akin to the high end programming.
♦ Perl is free to download from
the GNU website so it is very
easily accessible .
♦ Perl is also available for MS-
DOS,WIN-NT and Macintosh.
Basic Concepts
♦ Perl files extension .Pl
♦ Can create self executing scripts
♦ Advantage of Perl
♦ Can use system commands
♦ Comment entry
♦ Print stuff on screen
Basics
♦ Can make perl files self
executable by making first line
as #! /bin/perl.
– The extension tells the kernel that
the script is a perl script and the
first line tells it where to look
for perl.
♦ The -w switch tells perl to
produce extra warning messages
about potentially dangerous
constructs.
Basics
♦ The advantage of Perl is that you
dont have to compile create
object file and then execute.
♦ All commands have to end in ";" .
can use unix commands by using.
– System("unix command");
♦ EG: system("ls *");
– Will give the directory listing on
the terminal where it is running.
Basics
♦ The pound sign "#" is the symbol
for comment entry. There is no
multiline comment entry , so you
have to use repeated # for each
line.
♦ The "print command" is used to
write outputs on the screen.
– Eg: print "this is ece 902";
Prints "this is ece 902" on the
screen.It is very similar to printf
statement in C.
♦ If you want to use formats for
printing you can use printf.
How to Store Values
♦ Scalar variables
♦ List variables
♦ Push,pop,shift,unshift,reverse
♦ Hashes,keys,values,each
♦ Read from terminal, command line
arguments
♦ Read and write to files
Scalar Variables
♦ They should always be preceded
with the $ symbol.
♦ There is no necessity to declare
the variable before hand .
♦ There are no datatypes such as
character or numeric.
♦ The scalar variable means that it
can store only one value.
Scalar Variable
♦ If you treat the variable as
character then it can store a
character. If you treat it as
string it can store one
word . if you treat it as a
number it can store one
number.
♦ Eg $name = "betty" ;
– The value betty is stored in
the scalar variable $name.
Scalar Variable
♦ EG: print "$name n"; The
ouput on the screen will be
betty.
♦ Default values for all
variables is undef.Which is
equivalent to null.
List Variables
♦ They are like arrays. It can
be considered as a group of
scalar variables.
♦ They are always preceded by
the @symbol.
– Eg @names =
("betty","veronica","tom");
♦ Like in C the index starts
from 0.
List Variables
♦ If you want the second name you
should use $names[1] ;
♦ Watch the $ symbol here because
each element is a scalar
variable.
♦ $ Followed by the listvariable
gives the length of the list
variable.
– Eg $names here will give you the
value 3.
Push,pop,shift,Unshift,reverse
♦ These are operators operating on
the list variables.
♦ Push and pop treat the list
variable as a stack and operate on
it. They act on the higher
subscript.
– Eg push(@names,"lily") , now the
@names will contain
("betty","veronica","tom","lily").
– Eg pop(@names) will return "lily"
which is the last value. And @names
will contain
("betty","veronica","tom").
Push,pop,shift,Unshift,reverse
♦ Shift and unshift act on the
lower subscript.
– Eg unshift(@names,"lily"), now
@names contains
("lily","betty","veronica","tom").
– Eg shift(@names) returns "lily" and
@names contains
("betty","veronica","tom").
♦ Reverse reverses the list and
returns it.
Hashes,keys,values,each
♦ Hashes are like arrays but
instead of having numbers as
their index they can have any
scalars as index.
♦ Hashes are preceded by a %
symbol.
– Eg we can have %rollnumbers =
("A",1,"B",2,"C",3);
Hashes,keys,values,each
♦ If we want to get the rollnumber
of A we have to say
$rollnumbers{"a"}. This will
return the value of rollnumber of
A.
♦ Here A is called the key and the
1 is called its value.
♦ Keys() returns a list of all the
keys of the given hash.
♦ Values returns the list of all
the values in a given hash.
Hashes,keys,values,each
♦ Each function iterates over the
entire hash returning two scalar
value the first is the key and
the second is the value
– Eg $firstname,$lastname =
each(%lastname) ;
– Here the $firstname and the
$lastname will get a new key value
pair during each iteration
Read / Write to Files
♦ To read and write to files we
should create something called
handles which refer to the files.
♦ To create the handles we use the
OPEN command.
– Eg open(filehandle1,"filename");
Will create the handle called
FILEHANDLE1 for the file "filename".
♦ This handle will be used for
reading.
Read / Write to Files
– Eg open(filehandle2,">filename");
Will create the handle called
FILEHANDLE2 for the file "filename".
♦ This handle will be used for
writing.
♦ Watch out for the ">" symbol
before the filename. This
indicates that the file is opened
for writing.
Read / Write to Files
♦ Once the file handles have been
obtained . the reading and
writing to files is pretty
simple.
– Eg $linevalue = <FILEHANDLE1> ;
♦ This will result in a line being
read from the file pointed by the
filehandle and the that line is
stored in the scalar variable
$linevalue.
Read / Write to Files
♦ When the end of file is reached
the <FILEHANDLE1> returns a
undef.
– Eg print FILEHANDLE2 "$linevaluen";
♦ This will result in a line with
the value as in $linevalue being
written to the file pointed by
the filehandle2 .
♦ For closing a filehandle use
close(FILEHANDLE);
Control Structures
♦ If / unless statements
♦ While / until statements
♦ For statements
♦ Foreach statements
♦ Last , next , redo statements
♦ && And || as control structures
If / Unless
♦ If similar to the if in C.
♦ Eg of unless.
– Unless(condition){}.
♦ When you want to leave the
then part and have just an
else part we use unless.
While / Until / For
♦ While similar to the while of
C.
♦ Eg until.
– Until(some expression){}.
♦ So the statements are
executed till the condition
is met.
♦ For is also similar to C
implementation.
Foreach Statement
♦ This statement takes a list
of values and assigns them
one at a time to a scalar
variable, executing a block
of code with each successive
assignment.
– Eg: Foreach $var (list) {}.
Last / Next / Redo
♦ Last is similar to break
statement of C.
– Whenever you want to quit from a
loop you can use this.
♦ To skip the current loop use the
next statement.
– It immideately jumps to the next
iteration of the loop.
♦ The redo statement helps in
repeating the same iteration
again.
&& And || Controls
♦ Unless(cond1){cond2}.
– This can be replaced by
cond1&&cond2.
♦ Suppose you want to open a file
and put a message if the file
operation fails we can do.
– (Condition)|| print "the file cannot
be opened“;
♦ This way we can make the control
structures smaller and efficient.
Functions
♦ Function declaration
♦ Calling a function
♦ Passing parameters
♦ Local variables
♦ Returning values
Function Declaration
♦ The keyword sub describes the
function.
– So the function should start with
the keyword sub.
– Eg sub addnum { …. }.
♦ It should be preferably either in
the end or in the beginning of
the main program to improve
readability and also ease in
debugging.
Function Calls
♦ $Name = &getname();
♦ The symbol & should precede
the function name in any
function call.
Parameters of Functions
♦ We can pass parameter to the
function as a list .
♦ The parameter is taken in as a
list which is denoted by @_
inside the function.
♦ So if you pass only one parameter
the size of @_ list will only be
one variable. If you pass two
parameters then the @_ size will
be two and the two parameters can
be accessed by $_[0],$_[1] ....
More About Functions
♦ The variables declared in the
main program are by default
global so they will continue
to have their values in the
function also.
♦ Local variables are declared
by putting 'my' while
declaring the variable.
More About Functions
♦ The result of the last operation
is usually the value that is
returned unless there is an
explicit return statement
returning a particular value.
♦ There are no pointers in Perl but
we can manipulate and even create
complicated data structures.
Regular Expression
♦ Split and join
♦ Matching & replacing
♦ Selecting a different target
♦ $&,$', And $`
♦ Parenthesis as memory
♦ Using different delimiter
♦ Others
Split And Join
♦ Split is used to form a list from
a scalar data depending on the
delimiter.
♦ The default delimiter is the
space.
♦ It is usually used to get the
independent fields from a record.
.
– Eg: $linevalue = "R101 tom 89%";
$_ = $linevalue.
@Data = split();
Split and Join
♦ Here $data[0] will contain R101 ,
$data[1] tom , $data[2] 89%.
♦ Split by default acts on $_
variable.
♦ If split has to perform on some
other scalar variable.Than the
syntax is.
– Split (/ /,$linevalue);
♦ If split has to work on some
other delimiter then syntax is.
– Split(/<delimiter>/,$linevalue);
Special Vriables
♦ $& Stores the value which
matched with pattern.
♦ $' Stores the value which
came after the pattern in the
linevalue.
♦ $` Stores thte value which
came before the pattern in
the linevalue.
Split and Join
♦ Join does the exact opposite
job as that of the split.
♦ It takes a list and joins up
all its values into a single
scalar variable using the
delimiter provided.
– Eg $newlinevalue = join(@data);
Matching and Replacing
♦ Suppose you need to look for a
pattern and replace it with
another one you can do the same
thing as what you do in unix .
the command in perl is .
– S/<pattern>/<replace pattern>.
♦ This by default acts on the $_
variable.If it has to act on a
different source variable (Eg
$newval) then you have to use.
– Eg @newval=~s/<pattern>/<replace
pattern> .
Parenthesis As Memory
♦ Parenthesis as memory.
– Eg fred(.)Barney1); .
♦ Here the dot after the fred
indicates the it is memorry
element. That is the 1
indicates that the character
there will be replaced by the
first memory element. Which in
this case is the any character
which is matched at that
poistion after fred.
The End

More Related Content

What's hot

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
sana mateen
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
Rabin BK
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
leo lapworth
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
valuebound
 
LINUX:Control statements in shell programming
LINUX:Control statements in shell programmingLINUX:Control statements in shell programming
LINUX:Control statements in shell programming
bhatvijetha
 
Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
sana mateen
 
Mips1
Mips1Mips1
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
SQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and ProfitSQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and Profit
Karwin Software Solutions LLC
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
Sujith Kumar
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
Keshav Kumar
 
Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1
Dan Dascalescu
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
Praveen M Jigajinni
 
Mysql
MysqlMysql
Mysql
Rathan Raj
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 

What's hot (20)

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
LINUX:Control statements in shell programming
LINUX:Control statements in shell programmingLINUX:Control statements in shell programming
LINUX:Control statements in shell programming
 
Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
 
Mips1
Mips1Mips1
Mips1
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
SQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and ProfitSQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and Profit
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1Introduction To Catalyst - Part 1
Introduction To Catalyst - Part 1
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Mysql
MysqlMysql
Mysql
 
C programming - String
C programming - StringC programming - String
C programming - String
 

Viewers also liked

A PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATEA PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATE
Tushar Choudhary
 
An isas presentation on .net framework 2.0 by vikash chandra das
An isas presentation on .net framework 2.0 by vikash chandra dasAn isas presentation on .net framework 2.0 by vikash chandra das
An isas presentation on .net framework 2.0 by vikash chandra das
Vikash Chandra Das
 
Struts & hibernate ppt
Struts & hibernate pptStruts & hibernate ppt
Struts & hibernate ppt
Pankaj Patel
 
Introduction To Hibernate
Introduction To HibernateIntroduction To Hibernate
Introduction To Hibernate
ashishkulkarni
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
YAPC::Europe 2008 - Mike Astle - Profiling
YAPC::Europe 2008 - Mike Astle - ProfilingYAPC::Europe 2008 - Mike Astle - Profiling
YAPC::Europe 2008 - Mike Astle - Profiling
lokku
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
Tim Bunce
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
Lubomir Rintel
 
Introduction to perl_control structures
Introduction to perl_control structuresIntroduction to perl_control structures
Introduction to perl_control structures
Vamshi Santhapuri
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
sana mateen
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
Profiling with Devel::NYTProf
Profiling with Devel::NYTProfProfiling with Devel::NYTProf
Profiling with Devel::NYTProf
bobcatfish
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209
Tim Bunce
 
Perl Memory Use - LPW2013
Perl Memory Use - LPW2013Perl Memory Use - LPW2013
Perl Memory Use - LPW2013
Tim Bunce
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 

Viewers also liked (17)

A PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATEA PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATE
 
An isas presentation on .net framework 2.0 by vikash chandra das
An isas presentation on .net framework 2.0 by vikash chandra dasAn isas presentation on .net framework 2.0 by vikash chandra das
An isas presentation on .net framework 2.0 by vikash chandra das
 
Struts & hibernate ppt
Struts & hibernate pptStruts & hibernate ppt
Struts & hibernate ppt
 
Introduction To Hibernate
Introduction To HibernateIntroduction To Hibernate
Introduction To Hibernate
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
YAPC::Europe 2008 - Mike Astle - Profiling
YAPC::Europe 2008 - Mike Astle - ProfilingYAPC::Europe 2008 - Mike Astle - Profiling
YAPC::Europe 2008 - Mike Astle - Profiling
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
Introduction to perl_control structures
Introduction to perl_control structuresIntroduction to perl_control structures
Introduction to perl_control structures
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Profiling with Devel::NYTProf
Profiling with Devel::NYTProfProfiling with Devel::NYTProf
Profiling with Devel::NYTProf
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209
 
Perl Memory Use - LPW2013
Perl Memory Use - LPW2013Perl Memory Use - LPW2013
Perl Memory Use - LPW2013
 
Optička rešetka 17
Optička rešetka 17Optička rešetka 17
Optička rešetka 17
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 

Similar to Perl tutorial

PERL.ppt
PERL.pptPERL.ppt
PERL.ppt
Farmood Alam
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
Rakesh Mukundan
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
Roy Zimmer
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Andrea Telatin
 
newperl5
newperl5newperl5
newperl5
tutorialsruby
 
newperl5
newperl5newperl5
newperl5
tutorialsruby
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Mufaddal Haidermota
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
Qrembiezs Intruder
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
NBACriteria2SICET
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docx
ajoy21
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
NiladriDey18
 
Perl slid
Perl slidPerl slid
Perl slid
pacatarpit
 
perl course-in-mumbai
 perl course-in-mumbai perl course-in-mumbai
perl course-in-mumbai
vibrantuser
 
perl course-in-mumbai
perl course-in-mumbaiperl course-in-mumbai
perl course-in-mumbai
vibrantuser
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
worr1244
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
Nihar Ranjan Paital
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 

Similar to Perl tutorial (20)

PERL.ppt
PERL.pptPERL.ppt
PERL.ppt
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
newperl5
newperl5newperl5
newperl5
 
newperl5
newperl5newperl5
newperl5
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docx
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Perl slid
Perl slidPerl slid
Perl slid
 
perl course-in-mumbai
 perl course-in-mumbai perl course-in-mumbai
perl course-in-mumbai
 
perl course-in-mumbai
perl course-in-mumbaiperl course-in-mumbai
perl course-in-mumbai
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 

More from Manav Prasad

Experience with mulesoft
Experience with mulesoftExperience with mulesoft
Experience with mulesoft
Manav Prasad
 
Mulesoftconnectors
MulesoftconnectorsMulesoftconnectors
Mulesoftconnectors
Manav Prasad
 
Mule and web services
Mule and web servicesMule and web services
Mule and web services
Manav Prasad
 
Mulesoft cloudhub
Mulesoft cloudhubMulesoft cloudhub
Mulesoft cloudhub
Manav Prasad
 
Jpa
JpaJpa
Spring introduction
Spring introductionSpring introduction
Spring introduction
Manav Prasad
 
Json
Json Json
The spring framework
The spring frameworkThe spring framework
The spring framework
Manav Prasad
 
Rest introduction
Rest introductionRest introduction
Rest introduction
Manav Prasad
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 
Junit
JunitJunit
Xml parsers
Xml parsersXml parsers
Xml parsers
Manav Prasad
 
Xpath
XpathXpath
Xslt
XsltXslt
Xhtml
XhtmlXhtml
Css
CssCss
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
Manav Prasad
 
Ajax
AjaxAjax
J query
J queryJ query
J query
Manav Prasad
 
J query1
J query1J query1
J query1
Manav Prasad
 

More from Manav Prasad (20)

Experience with mulesoft
Experience with mulesoftExperience with mulesoft
Experience with mulesoft
 
Mulesoftconnectors
MulesoftconnectorsMulesoftconnectors
Mulesoftconnectors
 
Mule and web services
Mule and web servicesMule and web services
Mule and web services
 
Mulesoft cloudhub
Mulesoft cloudhubMulesoft cloudhub
Mulesoft cloudhub
 
Jpa
JpaJpa
Jpa
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Json
Json Json
Json
 
The spring framework
The spring frameworkThe spring framework
The spring framework
 
Rest introduction
Rest introductionRest introduction
Rest introduction
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
Junit
JunitJunit
Junit
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Xpath
XpathXpath
Xpath
 
Xslt
XsltXslt
Xslt
 
Xhtml
XhtmlXhtml
Xhtml
 
Css
CssCss
Css
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
 
Ajax
AjaxAjax
Ajax
 
J query
J queryJ query
J query
 
J query1
J query1J query1
J query1
 

Recently uploaded

Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
OnePlan Solutions
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service AvailableCall Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
sapnaanpad7
 
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
ns9201415
 
Photo Copier Xerox Machine annual maintenance contract system.pdf
Photo Copier Xerox Machine annual maintenance contract system.pdfPhoto Copier Xerox Machine annual maintenance contract system.pdf
Photo Copier Xerox Machine annual maintenance contract system.pdf
SERVE WELL CRM NASHIK
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
VictoriaMetrics
 
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
simmi singh$A17
 
1 Million Orange Stickies later - Devoxx Poland 2024
1 Million Orange Stickies later - Devoxx Poland 20241 Million Orange Stickies later - Devoxx Poland 2024
1 Million Orange Stickies later - Devoxx Poland 2024
Alberto Brandolini
 
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
tinakumariji156
 
European Standard S1000D, an Unnecessary Expense to OEM.pptx
European Standard S1000D, an Unnecessary Expense to OEM.pptxEuropean Standard S1000D, an Unnecessary Expense to OEM.pptx
European Standard S1000D, an Unnecessary Expense to OEM.pptx
Digital Teacher
 
Trailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptxTrailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptx
ImtiazBinMohiuddin
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Ortus Solutions, Corp
 
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable PriceCall Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
vickythakur209464
 
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
Anita pandey
 
SAP ECC & S4 HANA PPT COMPARISON MM.pptx
SAP ECC & S4 HANA PPT COMPARISON MM.pptxSAP ECC & S4 HANA PPT COMPARISON MM.pptx
SAP ECC & S4 HANA PPT COMPARISON MM.pptx
aneeshmanikantan2341
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)
wonyong hwang
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
Extreme DDD Modelling Patterns - 2024 Devoxx PolandExtreme DDD Modelling Patterns - 2024 Devoxx Poland
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
Alberto Brandolini
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
Zycus
 

Recently uploaded (20)

Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service AvailableCall Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
Call Girls Goa 💯Call Us 🔝 7426014248 🔝 Independent Goa Escorts Service Available
 
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Ahmedabad ✔ 7737669865 ✔ Hi I Am Divya Vip Call Girl Servic...
 
Photo Copier Xerox Machine annual maintenance contract system.pdf
Photo Copier Xerox Machine annual maintenance contract system.pdfPhoto Copier Xerox Machine annual maintenance contract system.pdf
Photo Copier Xerox Machine annual maintenance contract system.pdf
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
 
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
Top Call Girls Lucknow ✔ 9352988975 ✔ Hi I Am Divya Vip Call Girl Services Pr...
 
1 Million Orange Stickies later - Devoxx Poland 2024
1 Million Orange Stickies later - Devoxx Poland 20241 Million Orange Stickies later - Devoxx Poland 2024
1 Million Orange Stickies later - Devoxx Poland 2024
 
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
🔥 Kolkata Call Girls  👉 9079923931 👫 High Profile Call Girls Whatsapp Number ...
 
European Standard S1000D, an Unnecessary Expense to OEM.pptx
European Standard S1000D, an Unnecessary Expense to OEM.pptxEuropean Standard S1000D, an Unnecessary Expense to OEM.pptx
European Standard S1000D, an Unnecessary Expense to OEM.pptx
 
Trailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptxTrailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptx
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
 
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable PriceCall Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
Call Girls in Varanasi || 7426014248 || Quick Booking at Affordable Price
 
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
Premium Call Girls In Ahmedabad 💯Call Us 🔝 7426014248 🔝Independent Ahmedabad ...
 
SAP ECC & S4 HANA PPT COMPARISON MM.pptx
SAP ECC & S4 HANA PPT COMPARISON MM.pptxSAP ECC & S4 HANA PPT COMPARISON MM.pptx
SAP ECC & S4 HANA PPT COMPARISON MM.pptx
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)Hyperledger Besu 빨리 따라하기 (Private Networks)
Hyperledger Besu 빨리 따라하기 (Private Networks)
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
Extreme DDD Modelling Patterns - 2024 Devoxx PolandExtreme DDD Modelling Patterns - 2024 Devoxx Poland
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
 

Perl tutorial

  • 2. Why PERL ??? ♦ Practical extraction and report language ♦ Similar to shell script but lot easier and more powerful ♦ Easy availablity ♦ All details available on web
  • 3. Why PERL ??? ♦ Perl stands for practical extraction and report language. ♦ Perl is similar to shell script. Only it is much easier and more akin to the high end programming. ♦ Perl is free to download from the GNU website so it is very easily accessible . ♦ Perl is also available for MS- DOS,WIN-NT and Macintosh.
  • 4. Basic Concepts ♦ Perl files extension .Pl ♦ Can create self executing scripts ♦ Advantage of Perl ♦ Can use system commands ♦ Comment entry ♦ Print stuff on screen
  • 5. Basics ♦ Can make perl files self executable by making first line as #! /bin/perl. – The extension tells the kernel that the script is a perl script and the first line tells it where to look for perl. ♦ The -w switch tells perl to produce extra warning messages about potentially dangerous constructs.
  • 6. Basics ♦ The advantage of Perl is that you dont have to compile create object file and then execute. ♦ All commands have to end in ";" . can use unix commands by using. – System("unix command"); ♦ EG: system("ls *"); – Will give the directory listing on the terminal where it is running.
  • 7. Basics ♦ The pound sign "#" is the symbol for comment entry. There is no multiline comment entry , so you have to use repeated # for each line. ♦ The "print command" is used to write outputs on the screen. – Eg: print "this is ece 902"; Prints "this is ece 902" on the screen.It is very similar to printf statement in C. ♦ If you want to use formats for printing you can use printf.
  • 8. How to Store Values ♦ Scalar variables ♦ List variables ♦ Push,pop,shift,unshift,reverse ♦ Hashes,keys,values,each ♦ Read from terminal, command line arguments ♦ Read and write to files
  • 9. Scalar Variables ♦ They should always be preceded with the $ symbol. ♦ There is no necessity to declare the variable before hand . ♦ There are no datatypes such as character or numeric. ♦ The scalar variable means that it can store only one value.
  • 10. Scalar Variable ♦ If you treat the variable as character then it can store a character. If you treat it as string it can store one word . if you treat it as a number it can store one number. ♦ Eg $name = "betty" ; – The value betty is stored in the scalar variable $name.
  • 11. Scalar Variable ♦ EG: print "$name n"; The ouput on the screen will be betty. ♦ Default values for all variables is undef.Which is equivalent to null.
  • 12. List Variables ♦ They are like arrays. It can be considered as a group of scalar variables. ♦ They are always preceded by the @symbol. – Eg @names = ("betty","veronica","tom"); ♦ Like in C the index starts from 0.
  • 13. List Variables ♦ If you want the second name you should use $names[1] ; ♦ Watch the $ symbol here because each element is a scalar variable. ♦ $ Followed by the listvariable gives the length of the list variable. – Eg $names here will give you the value 3.
  • 14. Push,pop,shift,Unshift,reverse ♦ These are operators operating on the list variables. ♦ Push and pop treat the list variable as a stack and operate on it. They act on the higher subscript. – Eg push(@names,"lily") , now the @names will contain ("betty","veronica","tom","lily"). – Eg pop(@names) will return "lily" which is the last value. And @names will contain ("betty","veronica","tom").
  • 15. Push,pop,shift,Unshift,reverse ♦ Shift and unshift act on the lower subscript. – Eg unshift(@names,"lily"), now @names contains ("lily","betty","veronica","tom"). – Eg shift(@names) returns "lily" and @names contains ("betty","veronica","tom"). ♦ Reverse reverses the list and returns it.
  • 16. Hashes,keys,values,each ♦ Hashes are like arrays but instead of having numbers as their index they can have any scalars as index. ♦ Hashes are preceded by a % symbol. – Eg we can have %rollnumbers = ("A",1,"B",2,"C",3);
  • 17. Hashes,keys,values,each ♦ If we want to get the rollnumber of A we have to say $rollnumbers{"a"}. This will return the value of rollnumber of A. ♦ Here A is called the key and the 1 is called its value. ♦ Keys() returns a list of all the keys of the given hash. ♦ Values returns the list of all the values in a given hash.
  • 18. Hashes,keys,values,each ♦ Each function iterates over the entire hash returning two scalar value the first is the key and the second is the value – Eg $firstname,$lastname = each(%lastname) ; – Here the $firstname and the $lastname will get a new key value pair during each iteration
  • 19. Read / Write to Files ♦ To read and write to files we should create something called handles which refer to the files. ♦ To create the handles we use the OPEN command. – Eg open(filehandle1,"filename"); Will create the handle called FILEHANDLE1 for the file "filename". ♦ This handle will be used for reading.
  • 20. Read / Write to Files – Eg open(filehandle2,">filename"); Will create the handle called FILEHANDLE2 for the file "filename". ♦ This handle will be used for writing. ♦ Watch out for the ">" symbol before the filename. This indicates that the file is opened for writing.
  • 21. Read / Write to Files ♦ Once the file handles have been obtained . the reading and writing to files is pretty simple. – Eg $linevalue = <FILEHANDLE1> ; ♦ This will result in a line being read from the file pointed by the filehandle and the that line is stored in the scalar variable $linevalue.
  • 22. Read / Write to Files ♦ When the end of file is reached the <FILEHANDLE1> returns a undef. – Eg print FILEHANDLE2 "$linevaluen"; ♦ This will result in a line with the value as in $linevalue being written to the file pointed by the filehandle2 . ♦ For closing a filehandle use close(FILEHANDLE);
  • 23. Control Structures ♦ If / unless statements ♦ While / until statements ♦ For statements ♦ Foreach statements ♦ Last , next , redo statements ♦ && And || as control structures
  • 24. If / Unless ♦ If similar to the if in C. ♦ Eg of unless. – Unless(condition){}. ♦ When you want to leave the then part and have just an else part we use unless.
  • 25. While / Until / For ♦ While similar to the while of C. ♦ Eg until. – Until(some expression){}. ♦ So the statements are executed till the condition is met. ♦ For is also similar to C implementation.
  • 26. Foreach Statement ♦ This statement takes a list of values and assigns them one at a time to a scalar variable, executing a block of code with each successive assignment. – Eg: Foreach $var (list) {}.
  • 27. Last / Next / Redo ♦ Last is similar to break statement of C. – Whenever you want to quit from a loop you can use this. ♦ To skip the current loop use the next statement. – It immideately jumps to the next iteration of the loop. ♦ The redo statement helps in repeating the same iteration again.
  • 28. && And || Controls ♦ Unless(cond1){cond2}. – This can be replaced by cond1&&cond2. ♦ Suppose you want to open a file and put a message if the file operation fails we can do. – (Condition)|| print "the file cannot be opened“; ♦ This way we can make the control structures smaller and efficient.
  • 29. Functions ♦ Function declaration ♦ Calling a function ♦ Passing parameters ♦ Local variables ♦ Returning values
  • 30. Function Declaration ♦ The keyword sub describes the function. – So the function should start with the keyword sub. – Eg sub addnum { …. }. ♦ It should be preferably either in the end or in the beginning of the main program to improve readability and also ease in debugging.
  • 31. Function Calls ♦ $Name = &getname(); ♦ The symbol & should precede the function name in any function call.
  • 32. Parameters of Functions ♦ We can pass parameter to the function as a list . ♦ The parameter is taken in as a list which is denoted by @_ inside the function. ♦ So if you pass only one parameter the size of @_ list will only be one variable. If you pass two parameters then the @_ size will be two and the two parameters can be accessed by $_[0],$_[1] ....
  • 33. More About Functions ♦ The variables declared in the main program are by default global so they will continue to have their values in the function also. ♦ Local variables are declared by putting 'my' while declaring the variable.
  • 34. More About Functions ♦ The result of the last operation is usually the value that is returned unless there is an explicit return statement returning a particular value. ♦ There are no pointers in Perl but we can manipulate and even create complicated data structures.
  • 35. Regular Expression ♦ Split and join ♦ Matching & replacing ♦ Selecting a different target ♦ $&,$', And $` ♦ Parenthesis as memory ♦ Using different delimiter ♦ Others
  • 36. Split And Join ♦ Split is used to form a list from a scalar data depending on the delimiter. ♦ The default delimiter is the space. ♦ It is usually used to get the independent fields from a record. . – Eg: $linevalue = "R101 tom 89%"; $_ = $linevalue. @Data = split();
  • 37. Split and Join ♦ Here $data[0] will contain R101 , $data[1] tom , $data[2] 89%. ♦ Split by default acts on $_ variable. ♦ If split has to perform on some other scalar variable.Than the syntax is. – Split (/ /,$linevalue); ♦ If split has to work on some other delimiter then syntax is. – Split(/<delimiter>/,$linevalue);
  • 38. Special Vriables ♦ $& Stores the value which matched with pattern. ♦ $' Stores the value which came after the pattern in the linevalue. ♦ $` Stores thte value which came before the pattern in the linevalue.
  • 39. Split and Join ♦ Join does the exact opposite job as that of the split. ♦ It takes a list and joins up all its values into a single scalar variable using the delimiter provided. – Eg $newlinevalue = join(@data);
  • 40. Matching and Replacing ♦ Suppose you need to look for a pattern and replace it with another one you can do the same thing as what you do in unix . the command in perl is . – S/<pattern>/<replace pattern>. ♦ This by default acts on the $_ variable.If it has to act on a different source variable (Eg $newval) then you have to use. – Eg @newval=~s/<pattern>/<replace pattern> .
  • 41. Parenthesis As Memory ♦ Parenthesis as memory. – Eg fred(.)Barney1); . ♦ Here the dot after the fred indicates the it is memorry element. That is the 1 indicates that the character there will be replaced by the first memory element. Which in this case is the any character which is matched at that poistion after fred.
  翻译: