programming perl in unix course number : cit 370 week 3 prof. daniel chen

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

Upload: randolf-thomas

Post on 18-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

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

Programming Perl in UNIX

Course Number : CIT 370

Week 3

Prof. Daniel Chen

Page 2: 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)

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

Topics of Discussion About Perl Operators Mixing Data Types Precedence and Associativity Control Structures, Blocks, and

Compound Statements Decision Making – Conditional

Constructs Loops

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

Chapter 5: Where’s the Operators?

5.1 About Perl Operators 5.2 Mixing Data Types 5.3 Precedence and Associativity

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

5.1 About Perl Operators

An operator manipulates data objects called operands.

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

5.2 Mixing Date Types Data Conversion (overloading)

How Strings Are Converted to Numbers Table 5.1

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

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

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

5.3.3 Equality Operators Numeric

Table 5.6

String Table 5.7

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

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.

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

5.3.6 Arithmetic Operators

Table 5.9

Autoincrement and autodecrement operators Table 5.10

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

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

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

Chapter 6: If Only, Unconditionally, Forever

6.1 Control Structures, Blocks, and Compound Statements

6.2 Decision Making – Conditional Constructs

6.3 Loops

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

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.

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

Decision Making-Conditions Constructors if and unless Statements

The if Construct

The if/else Construct

The if/elseif/else Construct

The unless Construct

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

Loops The while loop

The until loop

The do/while and do/until Loops

The for Loop

The foreach Loop

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

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

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

Summary About Perl Operators Mixing Data Types Precedence and Associativity Control Structures, Blocks, and

Compound Statements Decision Making – Conditional

Constructs Loops

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

Lab

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

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

Quiz 1 Quiz Date: Today

Quiz Time: 11:00 AM - 11:30 AM

Contents: Chapter 1- Chapter 4

No books, no notes, no computer

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

Next Week

Reading assignment (Textbook chapter 7 and Chapter 8)