Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

# let's say that this reads from a previously-created counter file,
# IF one exists --- ELSE it creates one!

print "Content-type: text/plain", "\n\n";

# this is big'n'ugly --- let's stick it in a variable
$ctr_file = "class9_04_counter";

if (-e $ctr_file)
{
    open COUNTER, "< $ctr_file"
       or #die "Cannot open $ctr_file: $!";
          print "open of $ctr_file failed\n";

    chomp($ct = <COUNTER>);

    close COUNTER; # close reading filehandle
}
else
{
    # if DIDN'T exist === let's consider initial value
    # of $ct to be 0...

    $ct = 0;
}

# ...and now open writing filehandle (which will CREATE file, if
# didn't exist before...)
open COUNTER, "> $ctr_file"
   or #die "Cannot open $ctr_file for writing: $!";
      print "cannot open $ctr_file for writing\n";

$ct++;
print COUNTER "$ct\n";

close COUNTER; # close output filehandle


print "$ct";

exit(0);