COP3832, Fall 2001, Homework 2
Due: Monday 10/8 at the start of class
To hand in the assignment
-
Hand in a printout of the perl program
-
Hand in a printout of the three configuration files: httpd.conf, srm.conf,
access.conf.
-
Upload a text version of the perl program
-
Upload the three configuration files: httpd.conf, srm.conf, access.conf.
-
Send me an email with the URL to your web site.
Get your server running on mongoose. Create a simple home page in the
document root.
Write a perl program. The program will be executed from the command prompt
on mongoose. It will not be called from a web browser (you don't know how
to do that yet, so please don't try.)
Write a perl program that will display a menu like the following
1. Count Words
2. Process Numbers
3. Quit Program
Please make a selection:
The program will accept input and perform an action as described below. After
performing the action for the menu item, the menu will be displayed again.
Continue accepting input and performing an action until the user inputs 3.
After selecting option 3, display a count of how many times option 1 was
selected and a count of how many times option 2 was selected. The valid input
values are 1, 2, 3. If any other value is entered by the user, display an
appropriate error message and redisplay the menu.
Perform these actions for the selected menu item
-
Count Words
-
Prompt the user for the name of a file. The file should contain one word
per line. If the file exists, display a table of words and the number of
times each word appeared in the file. Display the words and their count in
alphabetical order of the words. For an extra point on the homework, also
display the words and their count in numeric order of the count. If the file
doesn't exist, display an error message. Do not distinguish between the case
of letters in a word: Apple, apple, APPLE would be three occurences of the
same word.
-
Process Numbers
-
Prompt the user for the name of a file. The file should contain one number
per line. Display the sum of all the numbers, the count of numbers, the maximum
number, the minimum number, and the average of all the numbers. Also display
a table that lists each number that is above the average, its distance above
the average, its distance above the minimum, and its distance below the maximum.
If the file doesn't exist, display an error message.
Notes
-
Use the strict pragma.
-
Use my variables for temporary variables inside of fuctions.
-
Make the tables look pretty by using printf. Use %12d to print
numbers in a column of 12 characters. Use %12s to print strings in
a column of 12 characters. Both will be right justified in the column. Use
%-12d and %-12s to do left justification.
-
Use functions. Be sure that the main program and all functions are less than
25 lines each.
-
Include comments to let me know what you think you are doing.
-
Include a comment at the top of the program stating that you did not give
nor receive help in completing this program with the exception of me. Sign
this statement on the printout that you submit to me.
-
Use the glob function to expand special characters (like ~, *) in
a filename. For instance
($filename) = glob $filename
Be sure to use the return value in a list context as ($filename) = glob $filename, or every other time you try to open a file, the open will fail.
These are a list of test files that you can use. I may use different files
to test your programs.
-
~downeyt/cs/public/text1.txt
-
~downeyt/cs/public/text2.txt
-
~downeyt/cs/public/num1.txt
-
~downeyt/cs/public/num2.txt
Here are some examples of the output:
Count Words |
Count Words Extra |
Process Numbers |
14 a
1 action
1 again
4 all
1 allows
1 along
1 also
1 an
2 and
1 appear
1 appears
6 are
4 as
7 assembly
3 assume
8 at
1 avery
1 back
2 be
1 because
2 branch
4 but
1 can
47 car
6 cars
1 case
11 complete
|
47 car
32 the
24 to
19 min
18 1
16 inst
14 a
14 4
14 2
12 it
11 would
11 station
11 complete
11 each
10 on
10 is
9 3
9 minutes
8 there
8 at
7 working
7 line
7 assembly
7 20
6 takes
|
average minimum maximum total count
47 2 99 1383 29
number delta avg delta max delta min
88 41 -11 86
90 43 -9 88
74 27 -25 72
99 52 0 97
95 48 -4 93
74 27 -25 72
83 36 -16 81
80 33 -19 78
80 33 -19 78
52 5 -47 50
86 39 -13 84
67 20 -32 65
96 49 -3 94
|