Perl

Menu

Homework 2

(The following assignment is based on a real-life situation that had arisen at my full-time job. Never say I don't show you what "real world" problems Perl helps with...)

A database table has been dumped out to a file, with each field separated by a pipe (The | character). In addition to several fields such as record number, size, username, and transaction, there are four fields which concern us. Three of these fields are "numeric_value", "character_value", and "date_value". For each record in the table, exactly one of these fields has a value - the others are NULL (which translates to a blank field in the file). The fourth field we are concerned with is the "field_type". This field can have possible values "N", "C", or "D", and tells us which of the other three fields will have a value. (That is, if field_type is "N", then the "numeric_value" field will contain a value, and character_value and date_value will both be empty.)

Write a validation tool to read the name of such a file (from the command line if provided, otherwise prompt the user and read the name of the file from STDIN) and ensure that these four fields have valid data. In particular, you must check three things:

  • The proper field in each record is populated, and the other two are blank
  • The numeric field contains an actual numeric value: A possible negative sign, followed by either an integer or a floating-point number (which will always have an integer portion)
  • The date field contains a valid date, in mm/dd/yyyy format. (For the purposes of this assignment, you need only ensure that date is the proper format, that the month is between 1 and 12, and that the date is between 1 and 31)
If any line of the file does not pass these three checks, output a warning (to STDERR) saying what is wrong with the line, being sure to specify what the line number of the file is. Then resume validating the remainder of the file.

Once you have finished validating the file, output a summary (to STDOUT) stating how many of each type of error was detected.

Notes

The field_type is the fifth field in the file. The numeric_value, character_value, and date_value are the seventh, eighth, and ninth fields in the file, respectively.

If you encounter any errors other than the three listed above, output an error message to STDERR and exit the program. Your programs should never crash or die unexpectedly.

Grading Criteria

Open the file and process each line 5
Obtain the field_type and three value fields 10
Detect incorrectly populated field(s) 17.5
Detect invalid numeric_value field 17.5
Detect invalid date_value field 20
Print summary information 10
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, empty inputs, invalid selections, 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.

This homework is due on Tuesday, October 4, 2005 at 11:59:59pm. It will be accepted until Wednesday, October 5 at 3:59:59pm for a deduction of 20 points

Perl Quotes
Perl Quotes