#!/usr/bin/perl use warnings; use strict; use Chatbot::Eliza; use LWP::UserAgent; use HTTP::Request; my $eliza = Chatbot::Eliza->new; my $ua = LWP::UserAgent->new; my $question = "How do you do? I am Dr. Eliza. Tell me about your problems."; # start value my $base_uri = 'http://askjeeves.com/main/askjeeves.asp'; my ($question_pre, $question_post, $reply_pre, $reply_post) = ('','','',''); my $HTML; $HTML = 1 if @ARGV; if ($HTML) { # Lazy HTML mode $question_pre="

"; $question_post="

"; $reply_pre="

"; $reply_post="

"; } foreach (1..50) { $question =~ s/[<>]//g; # shrug print "$question_pre$question$question_post\n\n"; $question =~ s/\s+/+/g; $question =~ s/\?//g; my $reply; until ($reply && $reply =~ /\w/) { my $request = HTTP::Request->new(GET=>"$base_uri?ask=$question"); my $page = $ua->request($request)->content; $page =~ /sans-serif">(.*?)<\/B>.*?(.*?)<\/font>/s; $reply = "$1\n$2"; } $question = $eliza->transform($reply); $reply =~ s/^(.*)$/$1<\/EM>/m if $HTML; print "$reply_pre$reply$reply_post\n\n"; warn "$reply\n"; }