SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Processing with Regular
Expressions
Find and Replace
• Thus far we have manipulated Perl RegEx’s Find feature but not it is
time to equip the Find and Replace functionality.
• Code: s/find/replace/
• Ex.
s/Godzilla/King Kong/; $temp =~ s/([a-z])/against $1’s team
• The find and replace functionality will only replace the first occurrence in the
string. In order to replace all occurrence you need to add a flag to mark it global.
• Code: g
• Ex. s/Godzilla/King Kong/g
s/// and m// similarities
• Create your own delimiters
• Ex. s/// s$$$ s%%%
• Ex. s//%% s@@** Can change individual groupings as long as pair is
consistent
• Substitution modifiers
• Flags i, x and s work, as well as them in combination with g
• Binding Operator
• Once again the default variable is checked against the s/// operator unless bound
to a different variable.
Case Shifting
• Sometimes when replacing a character or string you want it to be upper or lower case.
• Question: Why couldn’t you just place this in your search pattern?
• The following force the entire expression to shift their case:
• Forces all to uppercase
• Code: U s/(Jason|Frank)/U$1/gi;
• Forces all to lowercase
• Code: L
• Terminated the case shift in the middle of the expression
• Code: E
• The following force the following character to shift their case:
• Forces next character to uppercase
• Code: u
• Forces next character to lowercase
• Code: l
• ***Note: These escape sequence work in any string substitution as well not just find and replace.***
Updating Numerous Files
• We can update numerous files at once in Perl just like we used loops to
maneuver an entire directory in bash.
• In order to accomplish this there are 3 key items you need:
1. A way to get a file name – array, positional parameter, standard input
2. A backup file extension – temporary file for the update
3. The substitution – what to update
• The backup file type operator can be specified to any extension type you
want:
• Code : $^I
• Ex. $^I = “.bak”;
• Question: What type of loop should you use if your files are in an array?
Updating Numerous Files Example
#!/usr/bin/perl
use strict;
use warnings;
$^I = “.bak”;
While(<STDIN>)
{
s/^Author:.*/Author: Randal L. Schwartz/;
s/^Phone:.*n//;
s/^Date:.*/Date: $date/;
print;
}

Weitere ähnliche Inhalte

Was ist angesagt?

Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
Tri Truong
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
Raj Rajandran
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
arnolambert
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 

Was ist angesagt? (20)

UNIX - Class6 - sed - Detail
UNIX - Class6 - sed - DetailUNIX - Class6 - sed - Detail
UNIX - Class6 - sed - Detail
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 
Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
Functional programming in Javascript
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in Javascript
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
Object Range
Object RangeObject Range
Object Range
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 

Andere mochten auch (9)

More Perl Basics
More Perl BasicsMore Perl Basics
More Perl Basics
 
File I/O
File I/OFile I/O
File I/O
 
More Pattern Matching With RegEx
More Pattern Matching With RegExMore Pattern Matching With RegEx
More Pattern Matching With RegEx
 
Passing Arguments
Passing ArgumentsPassing Arguments
Passing Arguments
 
CSV File Manipulation
CSV File ManipulationCSV File Manipulation
CSV File Manipulation
 
Processing Regex Python
Processing Regex PythonProcessing Regex Python
Processing Regex Python
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Json
JsonJson
Json
 

Ähnlich wie Processing with Regular Expressions

BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide Summary
Ohgyun Ahn
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
JEEVANANTHAMG6
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
NiladriDey18
 
Mobile Software Engineering Crash Course - C02 Java Primer
Mobile Software Engineering Crash Course - C02 Java PrimerMobile Software Engineering Crash Course - C02 Java Primer
Mobile Software Engineering Crash Course - C02 Java Primer
Mohammad Shaker
 
Perl_Part1
Perl_Part1Perl_Part1
Perl_Part1
Frank Booth
 
Perl Development (Sample Courseware)
Perl Development (Sample Courseware)Perl Development (Sample Courseware)
Perl Development (Sample Courseware)
Garth Gilmour
 

Ähnlich wie Processing with Regular Expressions (20)

1 4 sp
1 4 sp1 4 sp
1 4 sp
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide Summary
 
LicĂŁo 13 functions
LicĂŁo 13 functionsLicĂŁo 13 functions
LicĂŁo 13 functions
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration
 
regex.ppt
regex.pptregex.ppt
regex.ppt
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
 
UNIT 3 python.pptx
UNIT 3 python.pptxUNIT 3 python.pptx
UNIT 3 python.pptx
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Mobile Software Engineering Crash Course - C02 Java Primer
Mobile Software Engineering Crash Course - C02 Java PrimerMobile Software Engineering Crash Course - C02 Java Primer
Mobile Software Engineering Crash Course - C02 Java Primer
 
Subprogram
SubprogramSubprogram
Subprogram
 
Perl_Part1
Perl_Part1Perl_Part1
Perl_Part1
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Perl Development (Sample Courseware)
Perl Development (Sample Courseware)Perl Development (Sample Courseware)
Perl Development (Sample Courseware)
 

Mehr von primeteacher32

Mehr von primeteacher32 (20)

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Returning Data
Returning DataReturning Data
Returning Data
 
Intro to Functions
Intro to FunctionsIntro to Functions
Intro to Functions
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Nested Loops
Nested LoopsNested Loops
Nested Loops
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
 
Input Validation
Input ValidationInput Validation
Input Validation
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
 
Nesting Conditionals
Nesting ConditionalsNesting Conditionals
Nesting Conditionals
 
Conditionals
ConditionalsConditionals
Conditionals
 
Intro to Python with GPIO
Intro to Python with GPIOIntro to Python with GPIO
Intro to Python with GPIO
 
Variables and Statements
Variables and StatementsVariables and Statements
Variables and Statements
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Hardware vs. Software Presentations
Hardware vs. Software PresentationsHardware vs. Software Presentations
Hardware vs. Software Presentations
 
Block chain security
Block chain securityBlock chain security
Block chain security
 
Hashes
HashesHashes
Hashes
 

KĂźrzlich hochgeladen

Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
amitlee9823
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
Ken Fuller
 
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
amitlee9823
 
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night StandCall Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
amitlee9823
 
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night StandCall Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
amitlee9823
 
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night StandCall Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
amitlee9823
 
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men 🔝Tirupati🔝 Escor...
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men  🔝Tirupati🔝   Escor...➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men  🔝Tirupati🔝   Escor...
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men 🔝Tirupati🔝 Escor...
amitlee9823
 
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
ZurliaSoop
 

KĂźrzlich hochgeladen (20)

TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
TEST BANK For Evidence-Based Practice for Nurses Appraisal and Application of...
 
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Chikkabanavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
 
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Nagavara Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
 
Personal Brand Exploration ppt.- Ronnie Jones
Personal Brand  Exploration ppt.- Ronnie JonesPersonal Brand  Exploration ppt.- Ronnie Jones
Personal Brand Exploration ppt.- Ronnie Jones
 
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night StandCall Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Devanahalli ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men  🔝Tumkur🔝   Escorts S...
➥🔝 7737669865 🔝▻ Tumkur Call-girls in Women Seeking Men 🔝Tumkur🔝 Escorts S...
 
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night StandCall Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Kengeri Satellite Town ☎ 7737669865 🥵 Book Your One night Stand
 
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
Chintamani Call Girls Service: ☎ 7737669865 ☎ High Profile Model Escorts | Ba...
 
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
 
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hoodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night StandCall Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Madiwala ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men  🔝bhavnagar🔝   Esc...
➥🔝 7737669865 🔝▻ bhavnagar Call-girls in Women Seeking Men 🔝bhavnagar🔝 Esc...
 
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men 🔝Tirupati🔝 Escor...
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men  🔝Tirupati🔝   Escor...➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men  🔝Tirupati🔝   Escor...
➥🔝 7737669865 🔝▻ Tirupati Call-girls in Women Seeking Men 🔝Tirupati🔝 Escor...
 
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
 
Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWN
 
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
 

Processing with Regular Expressions

  • 2. Find and Replace • Thus far we have manipulated Perl RegEx’s Find feature but not it is time to equip the Find and Replace functionality. • Code: s/find/replace/ • Ex. s/Godzilla/King Kong/; $temp =~ s/([a-z])/against $1’s team • The find and replace functionality will only replace the first occurrence in the string. In order to replace all occurrence you need to add a flag to mark it global. • Code: g • Ex. s/Godzilla/King Kong/g
  • 3. s/// and m// similarities • Create your own delimiters • Ex. s/// s$$$ s%%% • Ex. s//%% s@@** Can change individual groupings as long as pair is consistent • Substitution modifiers • Flags i, x and s work, as well as them in combination with g • Binding Operator • Once again the default variable is checked against the s/// operator unless bound to a different variable.
  • 4. Case Shifting • Sometimes when replacing a character or string you want it to be upper or lower case. • Question: Why couldn’t you just place this in your search pattern? • The following force the entire expression to shift their case: • Forces all to uppercase • Code: U s/(Jason|Frank)/U$1/gi; • Forces all to lowercase • Code: L • Terminated the case shift in the middle of the expression • Code: E • The following force the following character to shift their case: • Forces next character to uppercase • Code: u • Forces next character to lowercase • Code: l • ***Note: These escape sequence work in any string substitution as well not just find and replace.***
  • 5. Updating Numerous Files • We can update numerous files at once in Perl just like we used loops to maneuver an entire directory in bash. • In order to accomplish this there are 3 key items you need: 1. A way to get a file name – array, positional parameter, standard input 2. A backup file extension – temporary file for the update 3. The substitution – what to update • The backup file type operator can be specified to any extension type you want: • Code : $^I • Ex. $^I = “.bak”; • Question: What type of loop should you use if your files are in an array?
  • 6. Updating Numerous Files Example #!/usr/bin/perl use strict; use warnings; $^I = “.bak”; While(<STDIN>) { s/^Author:.*/Author: Randal L. Schwartz/; s/^Phone:.*n//; s/^Date:.*/Date: $date/; print; }

Hinweis der Redaktion

  1. Sometimes you are using a pattern fro the replace so if the pattern returns a lower or upper you might need to shift the case.
  2. Foreach if list of files in an array
  3. Foreach if list of files in an array