1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/perl
# This simple script implements a Chatbot::Eliza
# object in a cgi program. It uses the CGI.pm module
# written by Lincoln Stein.
#
# 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://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
use CGI;
use Chatbot::Eliza;
my $cgi = new CGI;
my $chatbot = new Chatbot::Eliza;
srand( time ^ ($$ + ($$ << 15)) ); # seed the random number generator
print $cgi->header;
print $cgi->start_html;
print $cgi->start_multipart_form;
print $cgi->h2('Eliza session');
# 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.
#
if ( $cgi->param() ) {
$prompt = $chatbot->transform( $cgi->param('Comment') );
} else {
$prompt = $chatbot->transform('Hello');
}
$cgi->param('Comment','');
print $cgi->h3($prompt),
$cgi->br,
$cgi->textarea( -name => 'Comment',
-wrap => 'yes',
-rows => 3,
-columns => 70 );
print $cgi->p,
$cgi->submit('Action','Send to Eliza'),
$cgi->reset('Reset');
print $cgi->endform;
print $cgi->end_html;
|