Text Processing Lab

CS 29

Mar. 6, 1997

ROT13

Write a program which interactively asks for a file name, then opens that file for reading. Then, ask for a second file name, and open that file for writing. If either open fails, the program should terminate with an error message.

Otherwise, read lines from the first file, perform the ROT13 translation upon each character in each line, then write the translated line to the second file. Upon receiving EOF from the first file, close both files and exit.

Notes:

  1. The ROT13 code translates ``a'' to ``n,'' ``A'' to ``N,'' ``b'' to ``o,'' etc.

  2. The disk file to use to test your program is /users/kelliher/pub/rot13 . Use pico to view you output file. If your program worked properly, you will be able to read the output file. You can use pico on the input file to verify that it contains ROT13 ``gibberish.''

  3. When using a keyboard for input, EOF is indicated by typing ctrl-d at the beginning of a line, but when using a file for input, EOF is indicated automatically when there are no more lines to read in the file.

De-Vowel

Write a program which interactively asks for a file name, then opens that file for reading. Then, ask for a second file name, and open that file for writing. If either open fails, the program should terminate with an error message.

Otherwise, read lines from the first file, remove all vowels from each line, using a substitution, then write the modified line to the second file. Upon receiving EOF from the first file, close both files and exit.

Notes:

  1. For this program, you use the substitution operation in place of the translation operation. The form of the substitution operation is this:
    $line =~ s/cat/dog/g;
    
    This will find all occurrences of cat in $line, replacing them with dog. In this example, cat is referred to as a regular expression and dog is referred to as a replacement string.

  2. You can use a character class within the regular expression so that each of several characters can be replaced by a single character:
    $line =~ s/[0123456789]/?/g
    
    All numerals in $line will be replaced by question marks.

  3. What will the following substitution accomplish?
    $line =~ s/hunger//g;
    



Thomas P. Kelliher
Wed Mar 5 16:59:55 EST 1997
Tom Kelliher