#!/usr/bin/perl -w

#######################################################
# class8_08_filehandle_output2
#
# adding using an output filehandle to class8_06_filehandle_input1
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 5-5-03
#######################################################

# let's say that this reads from a previously-created counter file

open COUNTER, "< /d3/home/faculty/st10/counters/class8_08_counter"
   or die "Cannot open class8_08_counter: $!";

chomp($ct = <COUNTER>);

print "current counter value is: $ct\n";

close COUNTER; # close reading filehandle

# ...and now open writing filehandle
open COUNTER, "> /d3/home/faculty/st10/counters/class8_08_counter"
   or die "Cannot open class8_08_counter for writing: $!";

$ct++;
print "reset counter to: $ct\n";
print COUNTER "$ct\n";

close COUNTER; # close output filehandle

# end of class8_08_filehandle_output2
