# to lock the file while writing to it, until closed
flock(LOG, 2) || Error('lock', 'file'); # this way two users don't simultaneously mess things up... flock(LOG,1) would request shared access to the file (for reading)

print LOG "$comments\n";

my @logmessages = <LOG>; # read the entire file into an array (each line an element)
while <LOG> {
#do such and such $_; } read the file line by line only
}
close(LOG) || Error('close','file');

print "Content-type: text/html\n\n";
print "<p>You said: <em>$comments</em>\n";
print qq(<hr>would you like to see all the <a href="http://www.cookwood.com/cgi-bin/perl2e/files/readfromlog.cgi">messages?</a>);

# change file or directory permissions
if(-e "public/archives"){
chmod(0777, "public/archives") || Error('change','permissions');
# this line is a good example of outputting something, anything to the browser to avoid a visible no output error!
print "<p>permissions have been changed";
}