#!/usr/bin/perl -w # Perl Chatbot Eliza # Terrence Ma # Modified from simple.cgi in Perl Module Chatbot::Eliza # 07/06/2000 # This simple script implements a Chatbot::Eliza # object in a cgi program. It uses the CGI.pm module. # # Needless to say, you must have the CGI.pm module # installed and working properly with CGI scripts on # your Web server before you can try to run this script. # CGI.pm is not included with Eliza.pm. # # Information about CGI.pm is here : # http://stein.cshl.org/WWW/software/CGI/ # # Information about Chatbot::Eliza is here : # http://search.cpan.org/search?dist=Chatbot-Eliza # check version, variable use 5.004; use strict; # add search path for local module Chatbot::Eliza use lib "/virtual/customer/terrence.com/htdocs/perllib"; use CGI::Pretty; use Chatbot::Eliza; # init objects my $cgi = new CGI; my $chatbot = new Chatbot::Eliza "Eliza", "elizadoctor.txt"; my $prompt; # seed random number generator srand(time ^ ($$ + ($$ << 15))); # print header print $cgi->header(), $cgi->start_html("Perl Chatbot Eliza"), $cgi->h2("Perl Chatbot Eliza"), $cgi->hr(), $cgi->br(); # These lines contain the "Eliza" functionality. # User comments are passed through the module's transform # method, and the output is used to prompt the user # for futher input. # get $param, generate $prompt if ($cgi->param()) { $prompt = $chatbot->transform($cgi->param("Comment") ); } else { $prompt = $chatbot->transform("Hello"); } $cgi->param("Comment",""); # print form print $cgi->start_form("get"); print $cgi->font("Eliza : "), $cgi->b($prompt), $cgi->br(), $cgi->br(); print $cgi->font("You : "), $cgi->textfield(-name => "Comment", -size => "55"), $cgi->font(" "), $cgi->submit(-name => "Action", -value => "Respond"), $cgi->br(), $cgi->br(); print $cgi->endform(); # print footer print $cgi->hr(), $cgi->a({-href=>"http://www.terrence.com/perl/eliza/eliza.txt"}, "Program Source"), $cgi->br(); print $cgi->end_html();