#!/usr/local/bin/perl ############################################################################# # Programmer : Bridget Thomson McInnes # # Description: A small program to simulate a Rogerian Psycotherapist. # Based off the Eliza program by Weizenbaum (1960). # # Usage: # perl doctor.pl # # Note: # this program badly lacks comments # ############################################################################## print "The doctor is in the house, what seems to be the problem?\n\n"; while() { chomp; $_ = lc($_); $_ =~s/[.!?,]//g; $_ =~s/\bI am\b/why are you/; $_ =~s/my\b ([a-zA-Z]+) is/why is your $1/i; $_ =~s/\bme\b/you/gi; $_ =~s/i\b/you/gi; $_ =~s/my\b/your/gi; $_ =~s/am\b/are/gi; $_ =~s/([A-Za-z]+\s)*\b?because\b(\s[A-Za-z]+)*/this seems to pose a problem, what do you think we should do about it?/i; $_ =~s/([A-Za-z]+\s)*\b?no\b(\s[A-Za-z]+)*/does this make you mad?/i; $_ =~s/([A-Za-z]+\s)*\b?yes\b(\s[A-Za-z]+)*/tell me why./i; $_ =~s/([A-Za-z]+\s)*\b?(kick|ass|jerk)\b(\s[A-Za-z]+)*/this is not a very grown up way to handle problems./i; $line = $_; if($line=~m/[.?!]/){ ; } else { $line .= "?"; } print "\n$line\n\n"; }