If you are a course participant, please send the solutions to these exercises to erikt@uia.ua.ac.be before or on Wednesday February 24, 2000. Note that the only the first three exercises are obligatory. When you submit your results, please include the Perl code you have written, the result of at least one test and the answers to the questions mentioned in the exercise.
Rot13 is an encryption method in which each of the 26 characters a-z is replaced by the character 13 places ahead or 13 places back in the alphabet. Write a program that reads a texts and outputs the rot13 equivalent. Example:
Enter a text, line by line. Finish with an empty line. > This text should be impossible to read > because it has been encrypted with a fine > encryption method. > Guvf grkg fubhyq or vzcbffvoyr gb ernq orpnhfr vg unf orra rapelcgrq jvgu n svar rapelcgvba zrgubq.
Note that since rot13 is symmetric, the same program can be used both for encoding and decoding.
Write a program that translates English text to text in some other language. It should at least be able to generate something reasonable for the words the, man, woman, boy, girl, telescope, sees, walks and with regardless of the context in which these words appear. Example:
Enter a text, line by line. Finish with an empty line. > The man sees the boy. > The woman walks with the girl > de man ziet de jongen. de vrouw loopt met het meisje.
The program may not use lists.
Make regular expressions for the following string descriptions:
You can test the expressions by putting them in a small program which tests whether an input string matches the expression or not.
Write a program that asks ten questions, reads the answers and shows the number of answers that were right. The questions should be like: Please enter n things in which n is an arbitrary number from 1 to 10 and things is one of the three words dollars, stars or commas. The questions should be chosen arbitrarily by the program. Example:
1. Please enter 3 dollars: $$$ Correct! 2. Please enter 7 stars: ****** Wrong. ... You have 7 correct answers on 10 questions.
Hint: Use the function rand.
Write a word tokenizer: a program which reads a text and outputs its words in the order that they appear in the text. Example:
Enter a text, line by line. Finish with an empty line. > In a drive-in I saw R2D2(TM). Funny, isn't it? > In a drive-in I saw R2D2 TM Funny isn't it
Test your program with as many problematic cases as you can think of.