Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.

Similar presentations


Presentation on theme: "Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen."— Presentation transcript:

1 Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen

2 Introduction n Review and Overviews n Chapters 5 and 6 n Summary n Lab n Quiz 1 n Next Week (Week 4)

3 Topics of Discussion n About Perl Operators n Mixing Data Types n Precedence and Associativity n Control Structures, Blocks, and Compound Statements n Decision Making – Conditional Constructs n Loops

4 Chapter 5: Where’s the Operators? n 5.1 About Perl Operators n 5.2 Mixing Data Types n 5.3 Precedence and Associativity

5 5.1 About Perl Operators n An operator manipulates data objects called operands.

6 5.2 Mixing Date Types n Data Conversion (overloading) n How Strings Are Converted to Numbers u Table 5.1

7 5.3 Precedence and Associativity n Precedence refers to the way is which the operator binds to its operand. n Associativity refers to the order in which an operator evaluates its operands: left to right, or right to left. u Table 5.2 n Assignment Operators u Table 5.3 n Relational Operators u Table 5.4

8 5.3.3 Equality Operators n Numeric u Table 5.6 n String u Table 5.7

9 5.3.4 Logical Operators n Unless C, the short-circuit operators do not return 0 (false) or 1 (true), but rather the value of the last operand evaluated. u Table 5.8 n Logical Word Operators (and, or, xor) u These logical word operators are of lower precedence than the short-circuit operators, but work the same way.

10 5.3.6 Arithmetic Operators Table 5.9 n Autoincrement and autodecrement operators u Table 5.10

11 Other Operators n Bitwise Logical Operators u TABLE 5.12 & Table 5.13 n Conditional Operators u Format: conditional expression ? expression : expression n Range Operator n Special String Operators and Functions u Table 5.14 n Generating Random Numbers u The rand/srand Functions

12 Chapter 6: If Only, Unconditionally, Forever n 6.1 Control Structures, Blocks, and Compound Statements n 6.2 Decision Making – Conditional Constructs n 6.3 Loops

13 Control Structures, Blocks, and Compound Statements n 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. n The looping constructs (while, for, foreach) allow the program to repetitively execute a statement block until some condition is satisfied. n A compound statement or block consists of a group of statements surrounded by curly braces. n Unlike C, Perl requires curly braces even one statement when that statement comes after the if, else, while, etc.

14 Decision Making-Conditions Constructors n if and unless Statements u The if Construct u The if/else Construct u The if/elseif/else Construct u The unless Construct

15 Loops n The while loop n The until loop n The do/while and do/until Loops n The for Loop n The foreach Loop

16 Loop Control n labels n next (continue) n last (break) n redo -it restarts the block without evaluating the loop expression again n goto n A Labeled Block Without a Loop n Nested Loops and Labels n The continue Block n The Phoney Switch Statement

17 Summary n About Perl Operators n Mixing Data Types n Precedence and Associativity n Control Structures, Blocks, and Compound Statements n Decision Making – Conditional Constructs n Loops

18 Lab n Examples 5.1 – 5.22 (P 101 – 129) n Examples 6.1 - 6.24 (P 133 - 161) n Homework 3

19 Quiz 1 n Quiz Date: Today n Quiz Time: 11:00 AM - 11:30 AM n Contents: Chapter 1- Chapter 4 n No books, no notes, no computer

20 Next Week n Reading assignment (Textbook chapter 7 and Chapter 8)


Download ppt "Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen."

Similar presentations


Ads by Google