<?xml version="1.0" encoding="windows-1252"?>
<node id="994212" title="Re: regarding google currency API" created="2012-09-18 03:17:20" updated="2012-09-18 03:17:20">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;The URL you provided does not provide valid JSON, so you'll have trouble feeding it to any of the standard Perl JSON modules.&lt;/p&gt;
&lt;p&gt;Ingy's recent work on [mod://JSONY] seems to be able to handle it though:&lt;/p&gt;
&lt;code&gt;
use 5.010;
use HTTP::Tiny;
use JSONY v0.0.3 qw(decode_jsony);

my $in_currency  = 'GBP';
my $out_currency = 'USD';

# Construct URL from currency codes
my $url = sprintf(
	'http://www.google.com/ig/calculator?hl=en&amp;q=1%s=?%s',
	$in_currency,
	$out_currency,
);

# Fetch URL and deal with HTTP errors
my $results = HTTP::Tiny-&gt;new-&gt;get($url);
die $results-&gt;{reason} unless $results-&gt;{success};

# Decode cruddy broken JSON and deal with decoding errors
my $data = decode_jsony($results-&gt;{content});
die $data-&gt;{error} if $data-&gt;{error};

# Print the result
say $data-&gt;{rhs};
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
994193</field>
<field name="parent_node">
994193</field>
</data>
</node>
