#!/usr/bin/perl -w use strict; use constant DEPTH=>9; use constant ENDCHANCE=>0.5; use constant MINLENGTH=>20; use constant MAXLENGTH=>200; # change the depth to change the quality of the output, higher values # are more faithful to the input text. Endchance determines the probability # that the output will stop at a period. You can change your input file # as desired below. Minlength prevents end of output before sending that many # characters. Maxlength forces end of output at next period after that many # characters. open FILE, "/usr/share/games/fortune/wisdom" || die "Find your fortune file!\n"; my $text=""; print "\n\nHail, O Aspirant! I am the almighty Oracle. I don't have time for\n"; print "pleasantries, so just type the topic of your consultation in one\n"; print qq~or two words.\n\n--O Oracle, tell me about: ~; while () { if ((!/--/)&&(!/^%/)) { # This is specifically for fortune files, which have -- before citations # and % separating lines. Change as necessary for your input. chomp; $text.="$_ "; } } my $start=; chomp($start); if (index($text,$start)<0) { my $position=int rand (length($text)/2); $position=index($text," ",$position); $start=substr($text,$position+1,DEPTH); } if (length($start)