You are on page 1of 64

Course 2:Programming

with Perl
By: Jayesh H. Munjani (159250)
Perl is a high-level, general-purpose,
interpreted, dynamic programming
language.

Perl language was specially designed

Introductio for text editing.

n to Perl Automation of the things done in


computer system related to job.

PERL can automate all these aspects,


so that we can spend time on other
important aspects of job.
Perl for ASIC

1 2 3 4 5
Creating Updating all Running testcases Running same test Developing
environment existing files for including with different Testcases.
files/removing some project compilation, configurations.
some of the files. specific updates. elaboration,
simulation.
Perl: Print and comment

Multiple line comment using =begin and =cut Comment a line using #
Perl: Single and Double quotes

Printing a variable value

Single and Double Quotes

Comment a line using #


Perl: Single and Double quotes

Printing email address with single and double Use of escape characters in print statement
quotes
“String” in Perl

Substring : 2nd character to end


String concatenation and repetition
2nd character to length of 2.
String comparison
Perl Variables: Scalers
($)
String to Number

Perl compiler automatic convert integer to


number if needed.
Perl
Variables:
Arrays (@)

Not be able to print “from” to


“to” index values.
Perl Variables: Hashes (%)
Standard Input <STDIN>

Take Input from the terminal and use it


Section 2:
Conditional
Statements
Comparator
s
If else statement

Find bigger Number from two given by user


Nested If else statement

Find bigger Number


from two given by
user
Unless

•If condition is false, then only inside


block will be executed.

•Its reverse of if condition.


For Loop
Foreach on Array
Foreach: for Hash
Foreach: on Hash
While Loop
Do While
Section 3: Perl Regular
Expressions
• Regular Expression (Regex or Regexp or RE) in Perl
Regular is a special text string for describing a search pattern
within a given text.
Expressions • It is used for pattern searching and Pattern
Matching.
String matching

String matching using =~


Match certain pattern

Using /pattern to match/


Using m[pattern to match]
Any character can be used instead of []
Replace matched pattern

Case sensitive search and match globally

Case insensitive search and match


Transliterate
Complex Regular Expressions
Complex Search

More than one character [a b]


Single character match a.

Other than [a b]
Complex Search

‘a’ with zero or more occurrence ‘a’ with 1 or more occurrence of ‘b’
of ‘b’

‘a’ with 0 or 1 occurrence of ‘b’


Complex Search

‘a’ with 2 occurrence of b ‘a’ with 2 or more occurrence of b


Complex Search

Any word using ‘\w’


Any digit using ‘\d’
\W for non words
\D for non numbers
Complex Search

White space using ‘\s’ Except White space using ‘\S’


Complex Search

Either a or b found then replace with X


Replace digit with length from 1 to 2
Complex string search
User Input and string match

Take strict user input from the terminal


Section 4: File
Handling
File Handling
Various
Modes for
File Handling
Read data from a
file and close it
•# Opening a File in Read-only mode
•open(r, "<", "Hello.txt");
Read a data and write •# Opening File in Write mode
data •open(w, ">", "Hello.txt");
Write a data
•# Opening File in Write mode
•open(w, ">>", "Hello.txt");
•# Opening File in Write mode
Append the data •open(a, ">>", "Hello.txt");
Read-Write Mode (rw, +>)
Read-Write Mode (rw, +>>)
Using File Handles
Reading a file content line by line
Arguments
Arguments: Factorial of a number
Switch and Argument
Section 4: Subroutines
Subroutine

A Perl function or subroutine is a group of statements that together


perform a specific task.

The word subroutines is used most in Perl programming because it


is created using keyword sub task.
Define and Call a Subroutine
Passing arguments to subroutine
Passing arguments to subroutine as array
Passing array as input
Different data type as input to function
Hash as input
Private Variable
Package in Perl
Thank You

You might also like