SlideShare a Scribd company logo
1 of 17
PERL
File Handling and Regex
FH – Opening a File

Opening a file :
open(file handler, filename);

3 Modes : Read, Write and Append

To open file in write mode
open(FH, >myfile.txt);

To open file in append mode
open(FH, >>myfile.txt);

Error handling
open(FH, myfile.txt) or die(“Could not open file : $! n”);

To read from File Handler
@filearr = <FH>;
FH – Writing to a File

Writing a statement to a file.
Print FH (“Writing to the filen”);

Closing a file
close(FH);

Perl automatically calls close, if we do not specify.
FH - seek

The seek function moves backward or forword in a file.
seek(FH, distance, relative_to);
distance is number of bytes to skip
relative_to could be either 0, 1 or 2
0 => From beginning of file
1 => From current position
2 => From end of file
FH – tell, read

Tell : Returns the distance, in bytes, between the beginning of the file and
the current position of the file.
tell(FH);

Read : enables us to read an aribtrary number of characters into a scalar
variable.
read(FH, result, length, offset);
result is the scalar variable into which the bytes are to be stored
lenght is the number of bytes to read
offset may be specified to place the read data at some place other than
beginning. A negative offset means, that many characters from end in
backward, a positive offset means that many from beginning forward.

read(FH,$scalar,80); # reads 80 bytes from the file represented by FH,
storing the resulting character string in $scalar
FH – other functions
getc : Reads a single character of input from file
$singlechar = getc(FH);

binmode : Tell the system that the file is a binary file. It must be called
after the file is opened and before read.
binmode(FH);

rename : Renames a file.
rename(oldname, newname);

unlink : Delete the file.
$num = unlink(@filelists); # It returns the number of files deleted.

mkdir : create directory
mkdir(“dirname”, permissions);

chdir(dirname) : Set the current working directory

rmdir(dirname) : Deletes an empty directory
FH – HERE docs

Print <<FH;
Hello I am here.
Welcome.
Bye.
FH
Regular Expressions
Basic RE

A regular expression is contained in slashes, and
matching occurs with the =~ operator. The following
expression is true if the string the appears in variable
$sentence.
$sentence =~ /the/

The RE is case sensitive, so if
$sentence = "The quick brown fox";
then the above match will be false.

The operator !~ is used for spotting a non-match. In
Special RE Characters
. # Any single character except a newline
^ # The beginning of the line or string
$ # The end of the line or string
* # Zero or more of the last character
+ # One or more of the last character
? # Zero or one of the last character
RE match examples

t.e # t followed by anthing followed by e
# This will match the
tre
tle
but not te, tale

^f# f at the beginning of a line

^ftp # ftp at the beginning of a line

e$ # e at the end of a line

tle$ # tle at the end of a line
RE match examples

and* # an followed by zero or more d characters
# This will match an
and
andd
anddd (etc)

.* # Any string without a newline. This is because the .
matches anything except a newline and the * means
zero or more of these.

^$ # A line with nothing in it.
More on RE

[qjk] # Either q or j or k

[^qjk] # Neither q nor j nor k

[a-z] # Anything from a to z inclusive

[^a-z] # No lower case letters

[a-zA-Z] # Any letter

[a-z]+ # Any non-zero sequence of lower case
letters

jelly|jam # Either jelly or jam

(eg|le)gs # Either eggs or legs

RE Special Characters

n # A newline

t # A tab

w # Any alphanumeric (word) character.
same as [a-zA-Z0-9_]

W # Any non-word character. same as [^a-
zA-Z0-9_]

d # Any digit, same as [0-9]

D # Any non-digit, same as [^0-9]

s # Any whitespace character: space, tab,
newline, etc
Substitution

To replace an occurrence of london by London in the
string $sentence we use the expression
$sentence =~ s/hello/Hello/

This example only replaces the first occurrence of the
string, and it may be that there will be more than one
such string we want to replace. To make a global
substitution the last slash is followed by a g as follows:
$sentence =~ s/hello/Hello/g

To ignore case and substitute.
$sentence =~ s/hello/Hello/gi
Translation

The tr function allows character-by-character
translation. The following expression replaces each a
with e, each b with d, and each c with f in the variable
$sentence. The expression returns the number of
substitutions made.
$sentence =~ tr/abc/edf/

To convert lower case to upper case
tr/a-z/A-Z/;
Remembering Patterns

remember patterns that have been matched so that
they can be used again.

anything matched in parentheses gets remembered in
the variables $1,...,$9.

These strings can also be used in the same regular
expression (or substitution) by using the special RE
codes 1,...,9.

More Related Content

What's hot

What's hot (20)

PAM : Point Accepted Mutation
PAM : Point Accepted MutationPAM : Point Accepted Mutation
PAM : Point Accepted Mutation
 
Cloning in eukaryotes
Cloning in eukaryotesCloning in eukaryotes
Cloning in eukaryotes
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Sequence Submission Tools
Sequence Submission ToolsSequence Submission Tools
Sequence Submission Tools
 
Bioinformatics data mining
Bioinformatics data miningBioinformatics data mining
Bioinformatics data mining
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Scoring matrices
Scoring matricesScoring matrices
Scoring matrices
 
NCBI National Center for Biotechnology Information
NCBI National Center for Biotechnology InformationNCBI National Center for Biotechnology Information
NCBI National Center for Biotechnology Information
 
Algorithm research project neighbor joining
Algorithm research project neighbor joiningAlgorithm research project neighbor joining
Algorithm research project neighbor joining
 
shotgun sequncing
 shotgun sequncing shotgun sequncing
shotgun sequncing
 
Database management system
Database management systemDatabase management system
Database management system
 
bacterial artificial chromosome & yeast artificial chromosome
bacterial artificial chromosome & yeast artificial chromosomebacterial artificial chromosome & yeast artificial chromosome
bacterial artificial chromosome & yeast artificial chromosome
 
A python web service
A python web serviceA python web service
A python web service
 
Statistical significance of alignments
Statistical significance of alignmentsStatistical significance of alignments
Statistical significance of alignments
 
Protein docking
Protein dockingProtein docking
Protein docking
 
Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)
 
Rapid amplification of c-DNA ends
Rapid amplification of c-DNA endsRapid amplification of c-DNA ends
Rapid amplification of c-DNA ends
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 
SEQUENCE ANALYSIS
SEQUENCE ANALYSISSEQUENCE ANALYSIS
SEQUENCE ANALYSIS
 
File in C language
File in C languageFile in C language
File in C language
 

Similar to Perl File Handling and Regex

Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line conceptsArtem Nagornyi
 
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 NeedsRoy Zimmer
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHBhavsingh Maloth
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on LinuxTushar B Kute
 
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
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl coursepartiernlow
 

Similar to Perl File Handling and Regex (20)

Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
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
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
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...
 
Perl
PerlPerl
Perl
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
 
First steps in PERL
First steps in PERLFirst steps in PERL
First steps in PERL
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Perl File Handling and Regex

  • 2. FH – Opening a File  Opening a file : open(file handler, filename);  3 Modes : Read, Write and Append  To open file in write mode open(FH, >myfile.txt);  To open file in append mode open(FH, >>myfile.txt);  Error handling open(FH, myfile.txt) or die(“Could not open file : $! n”);  To read from File Handler @filearr = <FH>;
  • 3. FH – Writing to a File  Writing a statement to a file. Print FH (“Writing to the filen”);  Closing a file close(FH);  Perl automatically calls close, if we do not specify.
  • 4. FH - seek  The seek function moves backward or forword in a file. seek(FH, distance, relative_to); distance is number of bytes to skip relative_to could be either 0, 1 or 2 0 => From beginning of file 1 => From current position 2 => From end of file
  • 5. FH – tell, read  Tell : Returns the distance, in bytes, between the beginning of the file and the current position of the file. tell(FH);  Read : enables us to read an aribtrary number of characters into a scalar variable. read(FH, result, length, offset); result is the scalar variable into which the bytes are to be stored lenght is the number of bytes to read offset may be specified to place the read data at some place other than beginning. A negative offset means, that many characters from end in backward, a positive offset means that many from beginning forward.  read(FH,$scalar,80); # reads 80 bytes from the file represented by FH, storing the resulting character string in $scalar
  • 6. FH – other functions getc : Reads a single character of input from file $singlechar = getc(FH);  binmode : Tell the system that the file is a binary file. It must be called after the file is opened and before read. binmode(FH);  rename : Renames a file. rename(oldname, newname);  unlink : Delete the file. $num = unlink(@filelists); # It returns the number of files deleted.  mkdir : create directory mkdir(“dirname”, permissions);  chdir(dirname) : Set the current working directory  rmdir(dirname) : Deletes an empty directory
  • 7. FH – HERE docs  Print <<FH; Hello I am here. Welcome. Bye. FH
  • 9. Basic RE  A regular expression is contained in slashes, and matching occurs with the =~ operator. The following expression is true if the string the appears in variable $sentence. $sentence =~ /the/  The RE is case sensitive, so if $sentence = "The quick brown fox"; then the above match will be false.  The operator !~ is used for spotting a non-match. In
  • 10. Special RE Characters . # Any single character except a newline ^ # The beginning of the line or string $ # The end of the line or string * # Zero or more of the last character + # One or more of the last character ? # Zero or one of the last character
  • 11. RE match examples  t.e # t followed by anthing followed by e # This will match the tre tle but not te, tale  ^f# f at the beginning of a line  ^ftp # ftp at the beginning of a line  e$ # e at the end of a line  tle$ # tle at the end of a line
  • 12. RE match examples  and* # an followed by zero or more d characters # This will match an and andd anddd (etc)  .* # Any string without a newline. This is because the . matches anything except a newline and the * means zero or more of these.  ^$ # A line with nothing in it.
  • 13. More on RE  [qjk] # Either q or j or k  [^qjk] # Neither q nor j nor k  [a-z] # Anything from a to z inclusive  [^a-z] # No lower case letters  [a-zA-Z] # Any letter  [a-z]+ # Any non-zero sequence of lower case letters  jelly|jam # Either jelly or jam  (eg|le)gs # Either eggs or legs 
  • 14. RE Special Characters  n # A newline  t # A tab  w # Any alphanumeric (word) character. same as [a-zA-Z0-9_]  W # Any non-word character. same as [^a- zA-Z0-9_]  d # Any digit, same as [0-9]  D # Any non-digit, same as [^0-9]  s # Any whitespace character: space, tab, newline, etc
  • 15. Substitution  To replace an occurrence of london by London in the string $sentence we use the expression $sentence =~ s/hello/Hello/  This example only replaces the first occurrence of the string, and it may be that there will be more than one such string we want to replace. To make a global substitution the last slash is followed by a g as follows: $sentence =~ s/hello/Hello/g  To ignore case and substitute. $sentence =~ s/hello/Hello/gi
  • 16. Translation  The tr function allows character-by-character translation. The following expression replaces each a with e, each b with d, and each c with f in the variable $sentence. The expression returns the number of substitutions made. $sentence =~ tr/abc/edf/  To convert lower case to upper case tr/a-z/A-Z/;
  • 17. Remembering Patterns  remember patterns that have been matched so that they can be used again.  anything matched in parentheses gets remembered in the variables $1,...,$9.  These strings can also be used in the same regular expression (or substitution) by using the special RE codes 1,...,9.