#!/usr/bin/perl -w ####################################################### # class8_07_filehandle_output1 # # now we'll add a message after reading the existing # messages (adding to class8_05_filehandle_input1) # # modified by Sharon Tuttle from "Learning Perl", # by Schartz and Phoenix # # last modified: 5-5-03 ####################################################### open PREV_MSGS, "< class8_07_msgs" or die "Cannot open class8_07_msgs: $!"; # show the current contents of this file while () { chomp($old_msg = $_); print "old message from file: $old_msg\n"; } close PREV_MSGS; # through reading from class8_07_msgs # now I want to open it for appending; open ALL_MSGS, ">> class8_07_msgs" or die "Cannot open class8_07_msgs for appending: $!"; # add a new message to the end of class8_07_msgs print "What message shall be added this time?\n"; chomp($new_msg = ); print ALL_MSGS "$new_msg\n"; close ALL_MSGS; # close appending filehandle # end of class8_07_filehandle_output1