Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: UTF8 fun and games again

by ultranerds (Friar)
on Oct 17, 2011 at 18:37 UTC ( #931992=note: print w/ replies, xml ) Need Help??


in reply to Re^4: UTF8 fun and games again
in thread UTF8 fun and games again

Ok, for anyone interested - its cos the JSON module needed to explicitly use the utf8 functions JSON->new->utf8 , and then also decode(). I've changed it to this, and it works perfectly now <G>

sub Do_Translate { my ($from,$to,$string) = @_; my $url = "https://www.googleapis.com/language/translate/v2?key=$k +ey&q=$string&source=$from&target=$to"; # print "getting URL: $url \n"; my $ua = LWP::UserAgent->new(); my $body = $ua->get($url); my $json = JSON->new->utf8; my $value = $json->decode( $body->decoded_content ); print "GOT: $value->{data}->{translations}[0]->{translatedText} \n +"; return utf8($value->{data}->{translations}[0]->{translatedText})-> +latin1; }


Comment on Re^5: UTF8 fun and games again
Download Code
Replies are listed 'Best First'.
Re^6: UTF8 fun and games again
by anneli (Pilgrim) on Oct 18, 2011 at 08:37 UTC

    Thanks for sharing your solution!

    Anne

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-29 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (261 votes), past polls