Lincoln D. Stein
Ah, for the good old days, when real programmers used
vi, networking software was written in C, and monolithic client/server applications ruled the Internet. Today, it’s easy to slap up a network application in a matter of minutes with a little CGI scripting, and if you are using a web authoring tool like Microsoft FrontPage, you can even write a serviceable network application without knowing any programming whatsoever.
Still, there are times when the web paradigm breaks down, and you need an application that has the immediacy and interactivity of an old-style client/server application, in which custom software on both sides of the connection exchange data using protocols designed specifically for the purpose at hand. The ease of writing client/server applications in Perl isn’t generally appreciated. In this article, I’ll show you how to do it.
Our running example uses the Chatbot::Eliza module, John Nolan’s marvelous purePerl clone of Joseph Weizenbaum’s classic psychotherapist simulation and the subject of his article in the third Best of TPJ book, Games, Diversions & Perl Culture. Chatbot::Eliza is available on CPAN and works very simply. It accepts a line of input from the user, transforms it according to a clever set of transformational rules, and echoes it back to the user in the form of a question. The effect is a lot like talking to a Freudian psychoanalyst, except that the conversation never seems to go anywhere.