http://qs321.pair.com?node_id=189385
Category: Fun Stuff
Author/Contact Info

jtarchie <thealienz123@yahoo.com>
AIM: thealienz123
ICQ: 5673454

Description:

This script requires use of the Win32::Clipboard Module.

This is the same as my tranls8it.com code, but has a built in interface for the Win32::Clipboard module. That way if you want to copy something into the clipboard, instead of typing it out again, the script will automatically translate whatever is in the clipboard, and write it over with the translation. I have it setup so, I can just use some shortcuts to do english<->lingo.

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTML::Form;
use Win32::Clipboard;

my $clip = Win32::Clipboard;
my $agent = new LWP::UserAgent;
my $url = 'http://www.transl8it.com/index.cgi?convert';
if($ARGV[0] eq '-to') {
    #Translates from english to text lingo
    print "English to lingo - \n";
    print "Type Message: ";
    my $input = '';
    if($clip->IsText()) {
        $input = $clip->GetText() . "\n";
        print $input;
    } else{
        $input = <STDIN>;
    }
    chomp($input);

    #Actual FORM post data
    my %data = (    'txtMessage' => $input,
            'direction' => '<--'
        );
    my $request = $agent->request(POST $url, [%data]);
    my $content = $request->content();
    my @forms = HTML::Form->parse($content, $url);
    foreach my $form (@forms) {
        eval{
            if(defined($form->value('txtTranslation'))) {
                print "\nTranslation: \n" . $form->value('txtTranslati
+on');
                $clip->Set($form->value('txtTranslation'));
                last;
            }
        };
        if(@_) {next;}
    }
} elsif($ARGV[0] eq '-from') {
    #Translates from text lingo to english
    print "lingo to English - \n";
    print "Type Message: ";
    my $input = '';
    if($clip->IsText()) {
        $input = $clip->GetText() . "\n";
        print $input;
    } else{
        $input = <STDIN>;
    }
    chomp($input);

    #Actual FORM post data
    my %data = (    'txtMessage' => $input,
            'direction' => '-->'
        );
    my $request = $agent->request(POST $url, [%data]);
    my $content = $request->content();
    my @forms = HTML::Form->parse($content, $url);
    foreach my $form (@forms) {
        eval{
            if(defined($form->value('txtTranslation'))) {
                print "\nTranslation: \n" . $form->value('txtTranslati
+on');
                $clip->Set($form->value('txtTranslation'));
                last;
            }
        };
        if(@_) {next;}
    }
} else{
    print 'perl trans.pl (-to|-from)';
}