Previous Page Next Page

8.5. What's Next?

In the next chapter, you will harness the power of pattern matching by learning Perl's plethora of regular expression metacharacters. You will learn how to anchor patterns, how to search for alternating patterns, whitespace characters, sets of characters, repeating patterns, etc. You will learn about greedy metacharacters and how to control them. You will learn about capturing and grouping patterns, to look ahead and behind. By the time you have completed this chapter, you should be able to search for data by regular expressions based on a specific criterion in order to validate the data and to modify the text that was found.

Exercise 8: A Match Made in Heaven

(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
Betty Boop:245–836–8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
William 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 all lines containing the pattern Street.
2.Print lines where the first name matches a B or b.
3.Print last names that match Ker.
4.Print phone numbers in the 408 area code.
5.Print Lori Gortz's name and address.
6.Print Ephram's name in capital letters.
7.Print lines that do not contain a 4.
8.Change William's name to Siegfried.
9.Print Tommy Savage's birthday.
10.Print the names of those making over $40,000.
11.Print the names and birthdays of those people born in June.
12.Print the zip code for Massachusetts.


Previous Page Next Page