#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
use XML::XPath;
use Data::Dumper;

use constant NOMRAL_DISPLAY => "\e[0;0m";
use constant UNDERLINE => "\e[0;4m";

use constant HOSTNAME => "http://services.aonaware.com";
use constant DICTIONARY => "gcide";
use constant STRATEGY => "lev";
use constant DEFINE_URL => 
	HOSTNAME . "/DictService/DictService.asmx/DefineInDict?dictId=" . DICTIONARY . "&word="; 

my $rawXml = get(DEFINE_URL . $ARGV[0]);
my $xp = XML::XPath->new(xml => $rawXml);
my $data = $xp->find('//Definition/WordDefinition');
if ($data->size == 0) {
  print "No Matches for $ARGV[0]\n";
} else {   
	my $count = 1;
	for my $def ($data->get_nodelist) { 
  	print UNDERLINE . "DEFINITION $count" . NOMRAL_DISPLAY . "\n";
  	print $def->string_value . "\n";
  	$count++;
	}
}

