CSC447: Concepts of Programming Languages

Homework Assignment 2(due Wednesday, September 25th)


Exercise 1: Write a Perl program that reads a string and a number. Lets say the string is 'hello' and the number is 3. The program should print:

Here is the string 'hello' printed 3 times:
hello
hello
hello

Exercise 2: Explain where in your program from exercise 1 type coercion is happening.

Exercise 3: Give an example of a Perl program where the fact that expressions can have side-effects causes unpredictable behavior. Try to come up with a different one than from lecture.

Exercise 4: Why aren't Perl style associative arrays available in C?

Exercise 5: Write a EBNF grammar for the if-else construct in Perl. You can use <expr> for expressions and <stmt> for statements.

Exercise 6: Write a Perl program to parse this mail file and create a file with all the headers on the first line and all the data values on the second line. Each field should be in quotes and the fields should be separated by commas. The resulting file should look something like this file. The first header should be "HW" and the first data value should be "1". Otherwise, it doesn't matter what order the headers appear in as long as they correspond correctly to the data values.