Perl

Menu

Homework 1

This homework is in two parts. It is designed so that you can do part A after the lecture on 9/7, and part B (and their combining) after the lecture on 9/14.

Part A

Prompt the user for the name of a file to open. Open the file if it exists, otherwise report an error and exit. The file will contain 2 numbers, separated by a space. Read in and save these two numbers.

Prompt the user for the name of a second file in which to store the output. Open this file for writing. Print to this file the results of four arithmatic operations on the two numbers from the first file.

For example, if the input file contains the line
5 3
Then your output file should contain the following four lines:
5 + 3 = 8
5 - 3 = 2
5 * 3 = 15
5 / 3 = 1.66666666666667

Part B

A list of directories will be specified on the command line. For each directory listed, open the directory, and examine the files within.

Maintain two lists. One list will record the number of files that have the same name. The other will record the number of filenames that start with each letter of the alphabet.

Once you have read all the file names, print the two lists. The first list (of file names) need not be in any particular order. It will simply state the name of the file and how many times that filename appeared in all the directories specified. The second list will be a list of the letters of the alphabet and how many filenames started with that letter. (If there are no file names for a particular letter, simply state "No filenames started with '<letter>'")

The list of starting-letters should be case insensitive. (file.txt and Foobar.pl both start with 'f'). The list of filename counts is case senstive. See sample input and output for examples.

Combining the Parts

Your program will be contained in one large if-else statement. If there are no command line arguments passed to the script, execute part A. If there are any command line arguments, execute part B.

Grading

A) Read name of input file from STDIN, and open 2.5
A) Read string from input file, and save numbers 10
A) Read name of output file, and open 2.5
A) Print four mathematical equations to output file 7.5
B) Open each directory from command line 5
B) Read list of files in each directory 5
B) Store list of filename counts 7.5
B) Store list of first-letter counts 15
B) Print filename counts 10
B) Print first-letter counts, sorted 12.5
Combine Part A & Part B 2.5
Compilation 5
Error Checking 5
Output Style 5
Code Style 5

Compilation

Your code should be developed with warnings enabled. Even if you do not enable warnings, the graders will. Any warnings that your code generates will result in deductions. If your code does not compile, all compilation points will be lost and the homework will be graded subjectively based on the code submitted. You should never submit code that does not compile.

Error Checking

Your code should never terminate unexpectedly. Check for all possible errors the user could make (non-existant file, non-existant directory, etc). When any user error occurs, exit gracefully with an appropriate error message

Output Style

Output style refers to how your output looks to the human eye. Data should be labeled, identifying what you're outputting. Output should be given in such a way as to be easily readable by a human being.

Code Style

Code Style is graded on how easily read your source code is. For generic tips on improving your code's style, read perldoc perlstyle. Most important are three criteria: meaningful variable names, consistent and helpful indentation, and explanitory but not over-abundant comments.

Submission

All homeworks are to be submitted via a program located on rcs-sun4.rpi.edu. You can develop your code whereever you like, but do make sure it works on rcs-sun4.rpi.edu using Perl 5.8 before attempting to submit.

When you are ready to submit, run the program ~lallip/public/hw_submit.pl on rcs-sun4.rpi.edu, and follow the prompts. Keep in mind that you may submit as many times as you need to. Only the final submission will be graded.

UPDATE

As a result of Paul's Screwup, this homework is now due on Friday, September 23, 2005 at 11:59:59pm.

Perl Quotes
Perl Quotes