<?xml version="1.0" encoding="windows-1252"?>
<node id="10239" title="webster client" created="2000-05-04 17:07:12" updated="2005-08-11 05:23:57">
<type id="1748">
sourcecode</type>
<author id="9316">
gregorovius</author>
<data>
<field name="doctext">
&lt;CODE&gt;
#!/usr/bin/perl -w

use HTML::TreeBuilder;
use HTML::FormatText;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua-&gt;agent("Dictionary");

#
# Uncomment if behind a firewall
#
#$ua-&gt;proxy([ 'http' ], 'http://www-dms.esd.sgi.com:8080/');

#
# Create a new request.
#
my $req = new HTTP::Request GET =&gt; "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=$ARGV[0]&amp;method=exact";

#
# Pass Request to the user agent and get a response back.
#
my $res = $ua-&gt;request($req);

#
# Print outcome of the response.
#
if(! $res-&gt;is_success) {
  print "Failure to connect to server: " . $res-&gt;message;
} else {
  my $html = $res-&gt;content;
  my $p = HTML::TreeBuilder-&gt;new;
  $p-&gt;parse($html);
  my $formatter = HTML::FormatText-&gt;new(leftmargin =&gt; 0, rightmargin =&gt; 60);
  my $result = $formatter-&gt;format($p);
  
  my @paragraphs = split /^\s+/m, $result;

  #
  # Print only the paragraphs where the word definition is
  #
  for(my $x=2; !($paragraphs[$x] =~ /^From WordNet/) and $x &lt; 10; $x++) {
    print $paragraphs[$x]."\n";
  } 
}

&lt;/CODE&gt;</field>
<field name="codedescription">
This is a simple web client that will bring a word 
definition from the UCSD web dictionary into your X 
terminal. &lt;BR&gt;&lt;BR&gt;
If people are interested I also have a 
server-simpler client version that allows this program
to be deployed on a large number of machines without
having to install the LWP and HTML packages it 
uses on each of them.
&lt;CODE&gt;
Usage:

% webster_client word
&lt;/CODE&gt;</field>
<field name="codecategory">
web robots</field>
<field name="codeauthor">
Claudio Garcia&lt;BR&gt;
claudio.garcia@stanfordalumni.org</field>
</data>
</node>
