Download presentation
Presentation is loading. Please wait.
Published byAmbrose Edwards Modified over 8 years ago
1
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen
2
Introduction n Review and Overviews n Chapter 4 n Summary n Lab n Quiz 1 n Next Week (Week 3)
3
Topics of Discussion n About Perl Variables n Scalars, Arrays, and Hashes n Reading from STDIN n Array Functions n Hash (Associative Array) Functions n More Hashes
4
Chapter 4: What’s in a Name n 4.1 About Perl Variables n 4.2 Scalars, Arrays, and Hashes n 4.3 Reading from STDIN n 4.4 Array Functions n 4.5 Hash (Associative Array) Functions n 4.6 More Hashes
5
4.1 About Perl variables n 4.1.1 Types u Scalar, Array, Hashes n 4.1.2 Scope and the Package u Package, Global Variables n 4.1.3 Naming Conventions u Case Sensitive n 4.1.4 Assignment Statements n 4.1.5 Quoting Rules u Single quotes u Double Quotes u Back Quotes u Perl’s Alternative Quotes (Table 4.1)
6
4.2 Scalars, Arrays, and Hashes n 4.2.1 Scalar Variables u Assignment u The undef Function n 4.2.2 Arrays u Special Scalars and Array Assignment u Accessing Elements u Array Slices u Multi-dimension Arrays – Lists of Lists n 4.2.3 Hashes u Accessing Elements u Hash Slices u Hashes of Hashes u Array of Hashes
7
4.3 Reading From STDIN n 4.3.1 Assigning Input to a Scalar Variable n 4.3.2 The chop and chomp Functions n 4.3.3 The read Function n 4.3.4 The getc Function n 4.3.5 Assigning Input to an Array n 4.3.6 Assigning Input to a Hash
8
4.4 Array Functions n The chop and chomp Functions (with Lists) n The exists Function n The delete Function n The grep Function n The join Function n The map Function n The pack and unpack Functions n The pop Function
9
Array Functions n The push Function n The shift Function n The delete Function n The splice Function n The split Function n The sort Function n The reverse Functions n The unshift Function
10
4.5 Hash (Associative Array) Functions n The keys Function n The values Function n The each Function n The delete Function n The exists Function
11
4. 6 More Hashes n 4.6.1 Loading a Hash from a File n 4.6.2 Special Hashes u The %ENV hash u The %SIG Hash u The %INC Hash n 4.6.3 Context
12
Matching a string or character at the beginning of a line with a ^ n using the ^ allows you to match words or characters at the beginning of the line only. n Two examples - ls -l ^d - ^…4XC….
13
Matching a string or character at the end of a line with a $ n The $ lets us match a string or character at the end of the line n Two examples - trouble$ - jet01$
14
Matching a single or string or character with * n The * allows us to match repeatedly any number of occurrences of any character or string n Two examples - compu*t (computer, computing, compuuuuuute) - 10133* (1013333, 10133, 1013444444)
15
Escaping the meaning of a special character with \ n Special characters ($. “ * [ ] | () \ + ?) n To disable the special character - Using \. - Using \*\.pas (*.pas)
16
Matching ranges or sets using [] n To match certain specific characters or range of characters use [] n Examples - [0-9] or [a-z] - [A-Za-z] - [A-Za-z0-9] - s[a-zA-Z]t - [Cc]omputer - [^a-zA-Z]
17
Matching a specific number of occurrences with \{\} n If you want to match only a certain number of occurrences, you can use \{ \} n pattern \{n\} (match n occurrences of the pattern) n pattern \[n,\} (match at least n occurrences of the pattern) n pattern \{n,m\} (match occurrences of the pattern between n and m, where n and m are integer numbers between 0 and 255) n Examples - A\{2\}B (AAB) - A\{4,\}B (AAAAAB) - A\{2,4\}B (2 As or 4As)
18
Summary n Perl Variables n Scalars, Arrays, and Hashes n Reading from STDIN n Array Functions n Hash Functions n Special Characters
19
Lab n Examples 4.1 – 4.59 (P 43 – 97) n Homework 2
20
Quiz 1 n Quiz Date: Next Week n Quiz Time: 11:00 AM - 11:30 AM n Contents: Chapter 1- Chapter 4 n No book, no note, no computer
21
Next Week n Reading assignment (Textbook chapters 5 and 6)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.