programming perl in unix course number : cit 370 week 3 prof. daniel chen
TRANSCRIPT
Programming Perl in UNIX
Course Number : CIT 370
Week 3
Prof. Daniel Chen
Introduction
Review and Overviews Chapters 5 and 6 Summary Lab Quiz 1 Next Week (Week 4)
Topics of Discussion About Perl Operators Mixing Data Types Precedence and Associativity Control Structures, Blocks, and
Compound Statements Decision Making – Conditional
Constructs Loops
Chapter 5: Where’s the Operators?
5.1 About Perl Operators 5.2 Mixing Data Types 5.3 Precedence and Associativity
5.1 About Perl Operators
An operator manipulates data objects called operands.
5.2 Mixing Date Types Data Conversion (overloading)
How Strings Are Converted to Numbers Table 5.1
5.3 Precedence and Associativity Precedence refers to the way is which the operator
binds to its operand.
Associativity refers to the order in which an operator evaluates its operands: left to right, or right to left. Table 5.2
Assignment Operators Table 5.3
Relational Operators Table 5.4
5.3.3 Equality Operators Numeric
Table 5.6
String Table 5.7
5.3.4 Logical Operators Unless C, the short-circuit operators do not return
0 (false) or 1 (true), but rather the value of the last operand evaluated. Table 5.8
Logical Word Operators (and, or , xor) These logical word operators are of lower
precedence than the short-circuit operators, but work the same way.
5.3.6 Arithmetic Operators
Table 5.9
Autoincrement and autodecrement operators Table 5.10
Other Operators Bitwise Logical Operators
TABLE 5.12 & Table 5.13
Conditional Operators Format: conditional expression ? expression :
expression
Range Operator
Special String Operators and Functions Table 5.14
Generating Random Numbers The rand/srand Functions
Chapter 6: If Only, Unconditionally, Forever
6.1 Control Structures, Blocks, and Compound Statements
6.2 Decision Making – Conditional Constructs
6.3 Loops
Control Structures, Blocks, and Compound Statements The decision-making constructs (if, if/else,
if/elsif/else, unless, etc.) contains a control expression that determines whether a block of statements will be executes.
The looping constructs (while, for, foreach) allow the program to repetitively execute a statement block until some condition is satisfied.
A compound statement or block consists of a group of statements surrounded by curly braces.
Unlike C, Perl requires curly braces even one statement when that statement comes after the if, else, while, etc.
Decision Making-Conditions Constructors if and unless Statements
The if Construct
The if/else Construct
The if/elseif/else Construct
The unless Construct
Loops The while loop
The until loop
The do/while and do/until Loops
The for Loop
The foreach Loop
Loop Control labels
next (continue)
last (break)
redo -it restarts the block without evaluating the loop expression again
goto
A Labeled Block Without a Loop
Nested Loops and Labels
The continue Block
The Phoney Switch Statement
Summary About Perl Operators Mixing Data Types Precedence and Associativity Control Structures, Blocks, and
Compound Statements Decision Making – Conditional
Constructs Loops
Lab
Examples 5.1 – 5.22 (P 101 – 129) Examples 6.1 - 6.24 (P 133 - 161) Homework 3
Quiz 1 Quiz Date: Today
Quiz Time: 11:00 AM - 11:30 AM
Contents: Chapter 1- Chapter 4
No books, no notes, no computer
Next Week
Reading assignment (Textbook chapter 7 and Chapter 8)