#!/usr/bin/perl -w ###################################### # # guestbook2.cgi # # Use CGI.pm for headers and some html code, and for parsing parameters. # Use a tied hash for the file input/output. # # - Jim Mahoney, Jan 2002 ####################################### use CGI; use CGI::Carp qw(fatalsToBrowser); # Send "die" messages to browser window my $cgi = new CGI; # One way of using CGI.pm - object oriented. print $cgi->header(); # standard CGI headers # Get the parameters. my $name = $cgi->param('name'); # Let CGI.pm do parsing of parameters. my $message = $cgi->param('message'); # This works for POST or PUT forms. # Perl has a "tie" function that replaces hash access # with file read write. In other words, once a hash is "tied", # then # $hash{key}="stuff"; # this writes to the file # $a = $hash{key}; # this reads from the file # The details for how the file is organized are handled by somebody else. use DB_File::Lock; my %guesthash; my $guestfile = 'guestbook2.db'; # Append the date and message to our guestbookfile # using a Berkely database file and a tied hash. if ($message and $name) { my $key = time() . $name; my $date = scalar localtime(); my $text = " Posted by '$name' on $date :
$message
| Your Name: | |
| Message: | |
| $gueststring |