SlideShare a Scribd company logo
Pattern Matching &
File Input and Output
Contents
■ Regex
■ Regex SpecialCharacters
■ Regex Example
■ Square brackets
■ Pattern Matching & Examples
■ File I/O
■ Open a File
■ Different Methods of Files
■ Reading &Writing and Append the Files
■ Closing the Files
What is Regex.?
■ Regex is a string of text that allows you to create patterns that
help match, locate, and manage text.
■ Perl is a great example of a programming language that utilizes
regular expressions.
■ Regular Expressions can also be used from the command line
and in text editors to find text within a file.
RegexSyntax
■ Regex was most popular with perl.
■ Regex are build in to perl.
■ However almost every language use regex.
■ Systax could have minor differences from
language to language.
Regex
code
Perl
compiler
outputregex engine
RegexSyntax
■ Regular expressions are used to perform pattern-matching and
“search-and-replace” functions on text.
■ Regex syntax:-
■ /pattern/modifiers
■ Creating a regular exp:-
■ var re = /pattern/modifiers ; or var re = new RegExp(”pattern”,
”modifiers”)
■ Modifiers
■ i,g,m
Regex Special Characters
Square brackets
Pattern Matching & Examples
Step:1 create .html file
Pattern Matching & Examples
Step:2 create .pl perl file and put the cgi-bin folder.
Pattern Matching & Examples
Step:3 write all validation into the .pl file
Username validation perform
/^[A-Z]/ = Start with uppercase.
Password validation perform
/^[A-Za-z_]w{7,14}$/
Phone number validation perform
/(7|8|9)d{9}/
Pattern Matching & Examples
.html file
Step:4 Run the .html file and perform action.
.pl file
File Input and Output
What is File input and output
■ Perl to read and update the data stored within the data stream
associated with the file handle.
■ A file handle is a named internal Perl structure that associates a
physical file with a name.
■ All file handles are capable of read/write access, so you can read
from and update any file or device associated with a file handle.
■ Three basic file handles are - STDIN, STDOUT,
and STDERR, which represent standard input, standard output
and standard error devices respectively.
Opening and Closing Files
■ There are following two functions with multiple forms, which can
be used to open any new or existing file in Perl.
■ Here FILEHANDLE is the file handle returned by the open function
and EXPR is the expression having file name and mode of opening
the file.
Opening Files
■ Opening files will used to open() function.
■ Following is the syntax to open file.txt in read-only mode.
■ Here DATA is the file handle, which will be used to read the file.
Here is the example, which will open a file and will print its
content over the screen.
Opening Files
Example:-
Closing Files
■ To close a file handle, and therefore disassociate the file handle
from the corresponding file, you use the close function.
■ If no FILEHANDLE is specified, then it closes the currently
selected file handle. It returns true only if it could successfully
flush the buffers and close the file.
Different methods Files
Reading and Writing and Append Files
■ Once you have an open file handle, you need to be able to read
and write information.
■ There are a number of different ways of reading and writing data
into the file.
Reading Files
■ Consider we have a Perl file with name file.txt and has few lines
of text in it.We need to open this file and print the same.
■ $_ The default variable without parameter.
Writing Files
■ Now that you know how to open and read files learning how to
write to them is straightforward.
Appending Files
■ The above way will always try to create a file named test.txt and
writes the input into the file. we will write the same to append
the file.
Copying Files
■ Here is the example, which opens an existing file file1.txt and
read it line by line and generate another copy file file2.txt.
Renaming Files
■ Here is an example, which shows how we can rename a file
file_rename.txt to file_name.txt.
Creating Files
■ Here is an example, which shows how we can Create a file inside
a folder. If file doesn't Exists.
Deleting an Existing File
■ Here is an example, which shows how to delete a file filedel.txt
using the unlink function.
References
■ http://www.oreilly.com/openbook/cgi/ch10_03.html
■ http://www.perlmonks.org/?node_id=857049
■ https://www.tutorialspoint.com/perl/perl_files.htm
■ http://www.troubleshooters.com/codecorn/littperl/perlfile.htm
■ http://slideplayer.com/slide/download/
■ http://www.cs.unc.edu/~jbs/resources/perl/perl-basics/io.html
■ http://www.techrepublic.com/article/validating-form-input-in-
perl-with-cgivalidate/
■ https://stackoverflow.com/questions/11926599/perl-form-
validation-using-cgi-scripting
Mehul Jariwala
MCA(General) 3rd Semester
Thanks you.

More Related Content

What's hot

Python data file handling
Python data file handlingPython data file handling
Python data file handling
ToniyaP1
 
Inverted index
Inverted indexInverted index
Inverted index
Krishna Gehlot
 
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter TreesExpediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
David Lillis
 
Inverted files for text search engines
Inverted files for text search enginesInverted files for text search engines
Inverted files for text search engines
unyil96
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data Structure
Prof Ansari
 
File organization continued
File organization continuedFile organization continued
File organization continued
chesterking12
 
File organization
File organizationFile organization
File organization
Ganesh Pawar
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
Zainab Almugbel
 
File Organization in Database
File Organization in DatabaseFile Organization in Database
File Organization in Database
A. S. M. Shafi
 
File structures
File structuresFile structures
File structures
Shyam Kumar
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 
Switching & Multiplexing
Switching & MultiplexingSwitching & Multiplexing
Switching & Multiplexing
MelkamuEndale1
 
1
11
Indexing
IndexingIndexing
File management
File managementFile management
File management
sumathiv9
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
Samuel Igbanogu
 
I/O PHP Files and classes
I/O PHP Files and classesI/O PHP Files and classes
I/O PHP Files and classes
Spy Seat
 
Introduction to php
Introduction  to  phpIntroduction  to  php
Introduction to php
leo paul
 
File organization
File organizationFile organization
File organization
RituBhargava7
 
Filehandling
FilehandlingFilehandling
Filehandling
Amandeep Kaur
 

What's hot (20)

Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
Inverted index
Inverted indexInverted index
Inverted index
 
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter TreesExpediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
Expediting MRSH-v2 Approximate Matching with Hierarchical Bloom Filter Trees
 
Inverted files for text search engines
Inverted files for text search enginesInverted files for text search engines
Inverted files for text search engines
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data Structure
 
File organization continued
File organization continuedFile organization continued
File organization continued
 
File organization
File organizationFile organization
File organization
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
File Organization in Database
File Organization in DatabaseFile Organization in Database
File Organization in Database
 
File structures
File structuresFile structures
File structures
 
File organization 1
File organization 1File organization 1
File organization 1
 
Switching & Multiplexing
Switching & MultiplexingSwitching & Multiplexing
Switching & Multiplexing
 
1
11
1
 
Indexing
IndexingIndexing
Indexing
 
File management
File managementFile management
File management
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
 
I/O PHP Files and classes
I/O PHP Files and classesI/O PHP Files and classes
I/O PHP Files and classes
 
Introduction to php
Introduction  to  phpIntroduction  to  php
Introduction to php
 
File organization
File organizationFile organization
File organization
 
Filehandling
FilehandlingFilehandling
Filehandling
 

Similar to Pattern matching & file input and output

File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in python
nitamhaske
 
Unit V.pptx
Unit V.pptxUnit V.pptx
Unit V.pptx
ShaswatSurya
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
ARYAN552812
 
File handling & regular expressions in python programming
File handling & regular expressions in python programmingFile handling & regular expressions in python programming
File handling & regular expressions in python programming
Srinivas Narasegouda
 
File handling in Python
File handling in PythonFile handling in Python
03-01-File Handling python.pptx
03-01-File Handling python.pptx03-01-File Handling python.pptx
03-01-File Handling python.pptx
qover
 
Presentation of file handling in C language
Presentation of file handling in C languagePresentation of file handling in C language
Presentation of file handling in C language
Shruthi48
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
vsol7206
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
Ananthi Palanisamy
 
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is hereCHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
sidbhat290907
 
Python file handling
Python file handlingPython file handling
Python file handling
Prof. Dr. K. Adisesha
 
file handling.pdf
file handling.pdffile handling.pdf
file handling.pdf
RonitVaskar2
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
Giovanni Marco Dall'Olio
 
File handing in C
File handing in CFile handing in C
File handing in C
shrishcg
 
Data File Handling in Python Programming
Data File Handling in Python ProgrammingData File Handling in Python Programming
Data File Handling in Python Programming
gurjeetjuneja
 
Working with files (concepts/pseudocode/python)
Working with files (concepts/pseudocode/python)Working with files (concepts/pseudocode/python)
Working with files (concepts/pseudocode/python)
FerryKemperman
 
Comp102 lec 11
Comp102   lec 11Comp102   lec 11
Comp102 lec 11
Fraz Bakhsh
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
Koteswari Kasireddy
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
Koteswari Kasireddy
 

Similar to Pattern matching & file input and output (20)

File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in python
 
Unit V.pptx
Unit V.pptxUnit V.pptx
Unit V.pptx
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
File handling & regular expressions in python programming
File handling & regular expressions in python programmingFile handling & regular expressions in python programming
File handling & regular expressions in python programming
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
03-01-File Handling python.pptx
03-01-File Handling python.pptx03-01-File Handling python.pptx
03-01-File Handling python.pptx
 
Presentation of file handling in C language
Presentation of file handling in C languagePresentation of file handling in C language
Presentation of file handling in C language
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is hereCHAPTER 2 - FILE HANDLING-txtfile.pdf is here
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
 
Python file handling
Python file handlingPython file handling
Python file handling
 
file handling.pdf
file handling.pdffile handling.pdf
file handling.pdf
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
 
File handing in C
File handing in CFile handing in C
File handing in C
 
Data File Handling in Python Programming
Data File Handling in Python ProgrammingData File Handling in Python Programming
Data File Handling in Python Programming
 
Working with files (concepts/pseudocode/python)
Working with files (concepts/pseudocode/python)Working with files (concepts/pseudocode/python)
Working with files (concepts/pseudocode/python)
 
Comp102 lec 11
Comp102   lec 11Comp102   lec 11
Comp102 lec 11
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
 

Recently uploaded

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 

Recently uploaded (20)

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 

Pattern matching & file input and output

  • 1. Pattern Matching & File Input and Output
  • 2. Contents ■ Regex ■ Regex SpecialCharacters ■ Regex Example ■ Square brackets ■ Pattern Matching & Examples ■ File I/O ■ Open a File ■ Different Methods of Files ■ Reading &Writing and Append the Files ■ Closing the Files
  • 3. What is Regex.? ■ Regex is a string of text that allows you to create patterns that help match, locate, and manage text. ■ Perl is a great example of a programming language that utilizes regular expressions. ■ Regular Expressions can also be used from the command line and in text editors to find text within a file.
  • 4. RegexSyntax ■ Regex was most popular with perl. ■ Regex are build in to perl. ■ However almost every language use regex. ■ Systax could have minor differences from language to language. Regex code Perl compiler outputregex engine
  • 5. RegexSyntax ■ Regular expressions are used to perform pattern-matching and “search-and-replace” functions on text. ■ Regex syntax:- ■ /pattern/modifiers ■ Creating a regular exp:- ■ var re = /pattern/modifiers ; or var re = new RegExp(”pattern”, ”modifiers”) ■ Modifiers ■ i,g,m
  • 8. Pattern Matching & Examples Step:1 create .html file
  • 9. Pattern Matching & Examples Step:2 create .pl perl file and put the cgi-bin folder.
  • 10. Pattern Matching & Examples Step:3 write all validation into the .pl file Username validation perform /^[A-Z]/ = Start with uppercase. Password validation perform /^[A-Za-z_]w{7,14}$/ Phone number validation perform /(7|8|9)d{9}/
  • 11. Pattern Matching & Examples .html file Step:4 Run the .html file and perform action. .pl file
  • 12. File Input and Output
  • 13. What is File input and output ■ Perl to read and update the data stored within the data stream associated with the file handle. ■ A file handle is a named internal Perl structure that associates a physical file with a name. ■ All file handles are capable of read/write access, so you can read from and update any file or device associated with a file handle. ■ Three basic file handles are - STDIN, STDOUT, and STDERR, which represent standard input, standard output and standard error devices respectively.
  • 14. Opening and Closing Files ■ There are following two functions with multiple forms, which can be used to open any new or existing file in Perl. ■ Here FILEHANDLE is the file handle returned by the open function and EXPR is the expression having file name and mode of opening the file.
  • 15. Opening Files ■ Opening files will used to open() function. ■ Following is the syntax to open file.txt in read-only mode. ■ Here DATA is the file handle, which will be used to read the file. Here is the example, which will open a file and will print its content over the screen.
  • 17. Closing Files ■ To close a file handle, and therefore disassociate the file handle from the corresponding file, you use the close function. ■ If no FILEHANDLE is specified, then it closes the currently selected file handle. It returns true only if it could successfully flush the buffers and close the file.
  • 19. Reading and Writing and Append Files ■ Once you have an open file handle, you need to be able to read and write information. ■ There are a number of different ways of reading and writing data into the file.
  • 20. Reading Files ■ Consider we have a Perl file with name file.txt and has few lines of text in it.We need to open this file and print the same. ■ $_ The default variable without parameter.
  • 21. Writing Files ■ Now that you know how to open and read files learning how to write to them is straightforward.
  • 22. Appending Files ■ The above way will always try to create a file named test.txt and writes the input into the file. we will write the same to append the file.
  • 23. Copying Files ■ Here is the example, which opens an existing file file1.txt and read it line by line and generate another copy file file2.txt.
  • 24. Renaming Files ■ Here is an example, which shows how we can rename a file file_rename.txt to file_name.txt.
  • 25. Creating Files ■ Here is an example, which shows how we can Create a file inside a folder. If file doesn't Exists.
  • 26. Deleting an Existing File ■ Here is an example, which shows how to delete a file filedel.txt using the unlink function.
  • 27. References ■ http://www.oreilly.com/openbook/cgi/ch10_03.html ■ http://www.perlmonks.org/?node_id=857049 ■ https://www.tutorialspoint.com/perl/perl_files.htm ■ http://www.troubleshooters.com/codecorn/littperl/perlfile.htm ■ http://slideplayer.com/slide/download/ ■ http://www.cs.unc.edu/~jbs/resources/perl/perl-basics/io.html ■ http://www.techrepublic.com/article/validating-form-input-in- perl-with-cgivalidate/ ■ https://stackoverflow.com/questions/11926599/perl-form- validation-using-cgi-scripting
  • 28. Mehul Jariwala MCA(General) 3rd Semester Thanks you.