CS 29
Mar. 6, 1997
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:
/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.''
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.
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:
$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.
$line =~ s/[0123456789]/?/gAll numerals in
$line
will be replaced by question marks.
$line =~ s/hunger//g;