#!/usr/bin/perl # dictionary.pl - lookup words in dictionary via web service # Eric Lease Morgan # 2006-08-20 - first cut use LWP; use XML::LibXML; use XML::LibXSLT; use strict; use constant DICTIONARY => 'http://services.aonaware.com/DictService/DictService.asmx/Define?word='; use constant DICT2HTML => '../etc/dict2html.xsl'; my $query = shift; my $html = ''; # create a user agent, create a request, send it, and get a response my $ua = LWP::UserAgent->new(agent => 'DICTIONARY-Client/0.1 '); my $request = HTTP::Request->new(GET => DICTIONARY . $query); my $response = $ua->request($request); # check response if ($response->is_success) { # create parser and process input my $parser = XML::LibXML->new; my $xslt = XML::LibXSLT->new; my $source = $parser->parse_string($response->content); my $style = $parser->parse_file( DICT2HTML ); my $stylesheet = $xslt->parse_stylesheet( $style ); my $results = $stylesheet->transform( $source ); # update the output print $stylesheet->output_string($results); } else { $html = $response->status_line, "\n" }