CSCI 4230
 Internet Application Development
 Fall 2001
 Homework #3

Due date: September 26, 2001 (Wednesday)

(1)    Write a function DepthFirstTraversal to accept an array and return a string of traversal of all elements in a depth first manner.  The leaf node is either a number or a string.  Each element is enclosed by a pair of double quotes and separated by two spaces.  For example, executing h3q1.pl:  (40%)

my @a = ('A', 'B', [1, 2, ['C', 'D'], ['X', [11, 13, 15], 'Y'], [30]], [], 400);
print DepthFirstTraversal(@a);
...
#    Definition of DepthFirstTraversal

will output:

"A"  "B"  "1"  "2"  "C"  "D"  "X"  "11"  "13"  "15"  "Y"  "30"  "400"

(2)    Write a Perl command line statement to weed out duplicate lines from an input file (e.g. somefile.txt) and store them into an output file (e.g. somefile_out.txt).  For example, for (20%)

somefile.txt:

a cat.
a dog.
A cat.
a cat.
a dog.
A DOG.
a rat.
a rat.
a cat.
a mouse.

after executing your Perl command line statement, the content of somefile_out.txt should be:

a cat.
a dog.
A cat.
A DOG.
a rat.
a mouse.

(3)    Write a program h3q3.pl to accept a data text file, h3q3dat.txt and use its data to create html output that may be used as part of a discussion board.  The data file stores one record per line using !! to separate its fields (40%):

node!!parent!!name!!email!!title

Assume no error in the data file.

For example, the contents of h3q3dat.txt:

1!!0!!Bun Yue!!yue@cl.uh.edu!!Hello
2!!1!!Susan Smith!!smith@cl.uh.edu!!RE: Hello
3!!1!!Thomas Jefferson!!tjefferson@hotmail.com!!RE: Hello
4!!3!!Susan Smith!!smith@cl.uh.edu!!RE: Hello
5!!0!!Nancy Boyd!!Boyd@cl.uh.edu!!A Perl Question
6!!4!!Nancy Boyd!!Boyd@cl.uh.edu!!RE: Hello
7!!5!!Thomas Jefferson!!tjefferson@hotmail.com!!RE: A Perl question
8!!7!!Carly Garfunkel!!garfunkel@yahoo.com!!RE: A Perl question
9!!1!!Susan Cox!!cox@cl.uh.edu!!RE: Hello

Executing your program should output:

<ul>
<li><a href="mailto:yue@cl.uh.edu">Bun Yue</a>: Hello</li>
<ul>
<li><a href="mailto:smith@cl.uh.edu">Susan Smith</a>: RE: Hello</li>
<li><a href="mailto:tjefferson@hotmail.com">Thomas Jefferson</a>: RE: Hello</li>
<ul>
<li><a href="mailto:smith@cl.uh.edu">Susan Smith</a>: RE: Hello</li>
<ul>
<li><a href="mailto:Boyd@cl.uh.edu">Nancy Boyd</a>: RE: Hello</li>
</ul>
</ul>
<li><a href="mailto:cox@cl.uh.edu">Susan Cox</a>: RE: Hello</li>
</ul>
<li><a href="mailto:Boyd@cl.uh.edu">Nancy Boyd</a>: A Perl Question</li>
<ul>
<li><a href="mailto:tjefferson@hotmail.com">Thomas Jefferson</a>: RE: A Perl question</li>
<ul>
<li><a href="mailto:garfunkel@yahoo.com">Carly Garfunkel</a>: RE: A Perl question</li>
</ul>
</ul>
</ul>

If the code is displayed in a browser, it looks like this:

For example, message #1 is in top level as its parent is 0.  Message #2 is a direct response to message #1, which is its parent, and so on.

Turn in source code listing, floppy disk containing all data and programs (so that the TA can directly test your program in disk A) and test output listing.  Name your files exactly as indicated to facilitate testing.  Everything should be put into an envelope.