Schwartz & Christiansen Chapter 7 Exercises


1.  Construct a regular expression that matches:
	a. at least one a followed by any number of b's
	b. any number of backslashes followed by any number of asterisks 
		(Any number = 0 or more)
	c. Three consecutive copies of whatever is contained in $whatever
	d. any five characters, including newline.
	e. the same word written two or more times in a row (with possibly
		varying intervening whitespace), where "word" is defined as a
		non-empty sequence of nonwhitespace characters.

2.	a. Write a program that accepts a list of words on STDIN and looks
		for a line containing all five vowels (a, e, i, o, u).  Run this program
		(called myprogram) on /usr/share/dict/words and see 
		what shows up.   In other words, enter:
		$ myprogram < /usr/share/dict/words
	b. Modify the program so that the five vowels must be in order and 
		intervening letters don't matter.
	c. Modify the program so taht all vowels must be in an increasing order,
		so all five vowels have to be present, and no "e" can occur before an "a",
		no "i" can occur before an "e", and so on.
		
3. Write a program that looks through /etc/passwd (on STDIN), printing the
	login name and real name of each user.  (Hint: Use split to break the line
	up into fields, then s/// to get rid of the parts of teh comment field that are
	after the first comma.)
	
4. Write a program that looks through /etc/passwd (on STDIN), for two users
	with the same first name, and prints those names.  (Hint: After extracting
	the first name, create a hash with the name for a key and the number of
	times it was seen as the value.  When the last line of STDIN has been read,
	look through the associative array for counts greater than one.)
	
5. Repeat the last exercise, but report the login names of all users with the 
	same first name.  (Hint: Instead of storing a count, store a list of login names
	separated by spaces.  When finished, look through the values for ones that
	contain a space.

Questions about the questions? Send mail to Robert Katz: katz@cis.highline.ctc.edu
Last Update January 26, 2000