Back to labs/answer key page

Add the test before opening the output file:

#Open the output file.

if (-e "$ARGV[0].out") {

   die "The output file already exists!";

} else {

   open(OUTPUT, ">$ARGV[0].out");

}

Opening the filehandle with the > at the beginning of the file name causes any existing file to be overwritten, so you must do the test first.

Back to labs/answer key page

-----

Emily M. Bender
Last modified: Fri Dec 8 11:59:16 2000