Previous Page Next Page

9.4. What's Next?

In the next chapter, we discuss how Perl deals with files, how to open them, read from them, write to them, append to them, and close them. You will learn how "die" works. You will learn how to seek to a position within a file, how to rewind back to the top, how to mark a spot for the next read operation. You will learn how to perform file tests to see if a file is readable, writeable, executable, etc. We will also discuss pipes, how Perl sends output to a pipe, and how Perl reads from a pipe. You will learn how to pass arguments to a Perl script at the command line and all the variations of ARGV.

Exercise 9: And the Search Goes On...

(Sample file found on CD)
Tommy Savage:408–724–0140:1222 Oxbow Court, Sunnyvale,CA
94087:5/19/66:34200
Lesle Kerstin:408–456–1234:4 Harvard Square, Boston, MA
02133:4/22/62:52600
JonDeLoach:408–253–3122:123 Park St., San Jose, CA 94086:7/25/53:85100
Ephram Hardy:293–259–5395:235 Carlton Lane, Joliet, IL
73858:8/12/20:56700
etty Boop:245–836–8357:635 Cutesy Lane, Hollywood, CA
91464:6/23/23:14500
Wilhelm Kopf:846–836–2837:6937 Ware Road, Milton, PA
93756:9/21/46:43500
Norma Corder:397–857–2735:74 Pine Street, Dearborn, MI
23874:3/28/45:245700
James Ikeda:834–938–8376:23445 Aster Ave., Allentown, NJ
83745:12/1/38:45000
Lori Gortz:327–832–5728:3465 Mirlo Street, Peabody, MA
34756:10/2/65:35200
Barbara Kerz:385–573–8326:832 Ponce Drive, Gary, IN
83756:12/15/46:268500

1.Print the city and state where Norma lives.
2.Give everyone a $250.00 raise.
3.Calculate Lori's age.
4.Print lines 2 through 6. (The $. variable holds the current line number.)
5.Print names and phone numbers of those in the 408 area code.
6.Print names and salaries in lines 3, 4, and 5.
7.Print a row of stars after line 3.
8.Change CA to California.
9.Print the file with a row of stars after the last line.
10.Print the names of the people born in March.
11.Print all lines that don't contain Karen.
12.Print lines that end in exactly five consecutive digits.
13.Print the file with the first and last names reversed.


Previous Page Next Page