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


In reply to Re: Google Translation using WWW::Babelfish by sk
in thread Google Translation using WWW::Babelfish by senik148

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.