CIS 33A Programming in PERL
Assignment E

Please staple the assignment together. At the top of the first page print, in this order: your first name, your last name, CIS33A, and the assignment letter. Print the problem number at the beginning of each problem. Assignments are due at the beginning of class, and will be marked down if turned in later.

Authorship note: These assignments have been adapted from assignments given by Clare Nguyen, who adapted them from the work of Behrouz Forouzan.

Programming Problems are to be done on the computer. Hand in your your source code and program output.

Programming problems

Problem E1

Each line in the /etc/passwd file has the following format:

login_name:passwd:userID:groupID:user's_real_name:home_directory:login_shell

Write a program that opens and reads the /etc/passwd file on voyager, and finds all "last names" that are shared by five to ten login_names.
The "last name" is the first word in the user's_real_name field (words are separated by white space).
Only print "last names" that have five to ten user id's with the same "last name".
Print these "last names" and all the corresponding login_name values.
Sort your output by last name.
Part of a sample output file is shown below.
Note that every name printed has five to ten login_name values.

Ngo : 11364782 trangngo99 toan223 jeffngo henrysg
Pham : setsunai ducky phamtastic0 mermaidsmilez loanpham sephirothdragon tpham903 cuongpham michaelduyen tpham8
Smith : bsmith06 smitha powersmiths casmith88 coreyosaur

This program must be tested on voyager.
Hint: instead of storing a count for each last name, store a string of login names separated by spaces. Then look for strings that contain five to ten login names.

Problem E2

Write a program that takes a paragraph of text. In the input paragraph, sentences end with a period, followed by optional white space. Words within a sentence are separated by white space. There are no new line characters.

Format the output so that each sentence is separated from the previous sentence by two spaces; words within a sentence are separated by one space; each sentence begins with a capital letter and the rest of the letters are to be in lower case. Put a new line at the end of the output.

Test with the following paragraph:

this paragraph was typed with no carriage returns.  this sentence is followed by a period and no space.This sentence is followed by a period and 7 spaces.       The following word is followed by a tab Fred	while the following word is followed by 6 spaces Mary      and the following word has crazy cases zEbRa.

Problem E3

Create a text file called   calendar   that looks like this:

11/17/1999 - Doctor's appointment.
12/6/1999 - Dentist appointment.
12/23/1999 - Christmas party.
1/23/2000 - Meet with business advisor.
1/13/2000 - Business trip to Hong Kong.
2/25/2000 - Business trip to Kansas City.
1/5/2000 - Car service.
3/18/2000 - Birthday party.
4/10/2000 - Meet with tax accountant.
3/12/2000 - Conference in San Jose.
12/31/1999 - New Year's party.

Write a program that opens and reads the calendar file. Then the program writes back in the calendar file the original content, sorted in ascending order by date.

The main code should be 7 lines of code, or less:

Use the sort function. In addition to the main code, you will need to code a sort subroutine that compares the dates of two records. This subroutine should be called by the sort function.