I ran your code and I get this output
soy mejicano con el pelo negro y los ojos marrones
If you want to store the output in a file then you can do something like this -
open (FH, '>', "junk") or die $!;
$en_text = $obj->translate( 'source' => 'English',
'destination' => 'Spanish',
'text' => "i am mexican with black hair an
+d brown eyes",
'delimiter' => "\n\n",
'ofh' => \*FH);
This will write the translation into a file.
If you do not want that then just remove the 'ofh' from the call. When i do that it returns the text and it is stored in $en_text. You can just print it or you can then push this text into an @array of your choice.
Something like this ? -
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Babelfish;
use Data::Dumper;
# open (FH, '>', "junk") or die $!;
my $obj = new WWW::Babelfish( service => 'Google', agent => 'Mozilla/
+8.0');
die( "Babelfish server unavailable\n" ) unless defined($obj);
my @sentences = ("I would like to translate this sentence into Spanis
+h", "Because i am mexican with black hair and brown eyes");
my @translations = ();
for (@sentences) {
my $en_text = $obj->translate( 'source' => 'English',
'destination' => 'Spanish',
'text' => $_,
'delimiter' => "\n\n");
die("Could not translate: " . $obj->error) unless defined($en_text
+);
push(@translations,$en_text);
}
print Dumper (@translations);
Output
$VAR1 = "Quisiera traducir esta oraci\x{f3}n a espa\x{f1}ol";
$VAR2 = 'Porque soy mejicano con el pelo negro y los ojos marrones';
-SK