synonym.pl - CLI for synonym.com -

#!/usr/bin/env perl
use strict;
use warnings;

=head1 DESCRIPTION

Command Line Interface for synonym.com

=head1 NAME

synonym.pl - command line interface for synonym.com

=head1 SYNOPSIS

  synonym.pl [word]

=head1 AUTHOR

t.koyachi

=cut

use LWP::UserAgent;

my $word = shift;
my $url = 'http://www.synonym.com/synonym/';
my $ua = LWP::UserAgent->new(timeout=> 10);

my $response = $ua->get($url . $word);
die "Can't load $url: ", $response->status_line
    unless $response->is_success;

my $doc = $response->content;
$doc =~ s!.*<pre>(.*?)</pre>.*!$1!xms;
my $head = "=" x 80 . "\n";

map {
    my $line = $_ . "\n";
    foreach my $keyword ('Synonyms \(Grouped by Similarity of Meaning\) of verb ',
                         'Overview of noun ',
                         'Overview of verb '
                     ) {
        if ($line =~ m!^$keyword(.*?)$!) {
            $line = $head . $line . $head;
            last;
        }
    }
    print $line;
} split /\n/, $doc;

もともとsynonym.comの結果自体がコマンドライン出力そのままな感じとはいえ、手抜きすぎか。