The first step in getting help is to be able to provide a clear problem statement, which you have not done.
What is the exact wording of the error message?
At what point do you receive that error?
Exactly how are you executing your script?
When you say:
i cannot get my code to connect to my installed script
That tells me that the initial problem has nothing to do with the code you posted and doesn't make a lot of sense.
$translate=$_POST['translate'];
That is not valid Perl code. It appears to be PHP code.
Do you have the following 2 lines in your script?
use strict;
use warnings;
If not, add them and run your script.
#!/usr/bin/perl
use strict; use warnings;
use WWW::Babelfish;
use Getopt::Long;
use IO::Prompt;
# map the language codes
my %language_code = (
fr => 'French',
es => 'Spanish',
de => 'German'
);
# parse command line arguments
my $translate_to_code;
my $result = GetOptions(
'translate-to=s' => $translate_to_code,
);
if (not $result) {
die "usage: ./translator.pl --translate-to fr | es | den";
}
if (not defined $translate_to_code) {
die "usage: ./translator.pl --translate-to fr | es | den";
}
if ($translate_to_code !~ /(fr)|(es)|(de)/) {
die "usage: ./translator.pl --translate-to fr | es | den";
}
# print instructions
print "nn";
print "Interactive Language Translator.n";
print "Enter text to translate at prompt.n";
print "Type 'EXIT' to quit.nn";
# create the Babelfish service
warn "Connecting to Babelfish service ...n";
my $service = WWW::Babelfish->new(
service => 'Babelfish',
);
# check for errors
if (not defined $service) {
die "Babelfish server unavailablen";
}
# loop while input is available
while ( prompt "text> " ) {
chomp;
# check if we need to exit
if ($_ =~ /^EXIT$/i) {
warn "Exiting ...n";
exit;
}
# translate
warn "Translating ...n";
my $translated_text = $service->translate(
source => 'English', # source language
destination => $language_code{$translate_to_code}, # destination language
text => $_ # text to translate
);
if (not defined $translated_text) {
warn "Error while translating.n";
}
else {
# output the translated text
print "[" . uc $translate_to_code . "] $translated_textn";
}
}