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

#######################################################
# lect06_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: 9-28-04
#######################################################

open PREV_MSGS, "< lect06_07_msgs"
   or die "Cannot open lect06_07_msgs: $!";

# show the current contents of this file

while (<PREV_MSGS>)
{
    chomp($old_msg = $_);

    print "old message from file: $old_msg\n";
}

close PREV_MSGS; # through reading from lect06_07_msgs


# now I want to open it for appending; 

open ALL_MSGS, ">> lect06_07_msgs"
   or die "Cannot open lect06_07_msgs for appending: $!";

# add a new message to the end of lect06_07_msgs

print "What message shall be added this time?\n";
chomp($new_msg = <STDIN>);

print ALL_MSGS "$new_msg\n";

close ALL_MSGS; # close appending filehandle

# end of lect06_filehandle_output1