Exchange Rate API

Perl Currency API

Our service is the easy to use, accurate and reliable currency API for Perl that's perfect for both personal and professional use. Easily convert currencies in your Perl project!

How to use our Perl Currency Converter

Converting currencies using our Perl Exchange Rate API is as easy as posting a HTTP request. Your requests would need to follow this simple pattern:

http://www.exchangerate-api.com/FROM_CURRENCY/TO_CURRENCY/AMOUNT?k=YOUR_API_KEY


Here are some examples in Perl:

1. Simple Currency Conversion (in Perl):

To convert from 12.50 USD (US Dollar) to GBP (British Pound):

#!/usr/bin/perl
use LWP 5.64;
$browser = LWP::UserAgent->new;
$from = "usd";
$to = "gbp";
$amount = 12.50;
$response = $browser->get('http://www.exchangerate-api.com/'.$from.'/'.$to.'/'.$amount.'?k=API_KEY');
print $response->content;

Or to get how many Japanese Yen (JPY) there are to the South African Rand (ZAR):

#!/usr/bin/perl
use LWP 5.64;
$browser = LWP::UserAgent->new;
$response = $browser->get('http://www.exchangerate-api.com/zar/jpy/?k=API_KEY');
print $response->content;

Error Codes:

The API returns the following error codes:
  -1 if an invalid amount is used (must be numeric floating point or integer numbers)
  -2 if either of the 3 letter currency codes are invalid (Check our supported currencies)
  -3 if an invalid key is used (Get an API key)
  -4 if your monthly API query limit is reached (Click here for extended usage)
  -5 if an unresolvable IP address is provided (This only applies for our "Automatic Country/Flag Information" query.)



We also offer two additional types of query:




2. Automatic Currency Detection/Conversion (in Perl):

To convert from 12.50 USD (US Dollar) to your user's currency:

#!/usr/bin/perl
use LWP 5.64;
$browser = LWP::UserAgent->new;
$ip = $ENV{'REMOTE_ADDR'};

$url = 'http://www.exchangerate-api.com/auto/USD/'.$ip.'/12.50'?k=API_KEY'; $response = $browser->get($url);
$result = $response->content;

@result_array = split('\|', $result);
$converted_amount = $result_array[0];
$symbol_unicode = $result_array[1];
$currency_code = $result_array[2];

print $converted_amount; #FINAL CONVERTED AMOUNT
print $currency_code; #FINAL 3-DIGIT CURRENCY CODE (EG: USD)

#If you want to display the currency's symbol in HTML:
$symbol_html = "";
@symbol_characters = split(',', $symbol_unicode);
foreach $symbol_characters(@symbol_characters) {
    $symbol_html = $symbol_html."&#".$symbol_characters.";";
    }
print $symbol_html; #FINAL SYMBOL HTML (EG: $)

Free 14-Day Trial

Sign Up Now!

Get started right away!



3. Automatic Country/Flag Information (in Perl):

To retrieve your user's national flag and other country information:

#!/usr/bin/perl
use LWP 5.64;
$browser = LWP::UserAgent->new;
$ip = $ENV{'REMOTE_ADDR'};

$url = 'http://www.exchangerate-api.com/country_info/'.$ip.'?k=API_KEY'; $response = $browser->get($url);
$result = $response->content;

@result_array = split('\|', $result);
$country_name = $result_array[0];
$country_code_2 = $result_array[1];
$country_code_3 = $result_array[2];
$currency_code = $result_array[3];
$symbol_unicode = $result_array[4];
$flag_url = $result_array[5];

print $country_name; #FINAL COUNTRY NAME
print $country_code_2; #FINAL 2-DIGIT COUNTRY CODE (EG: US)
print $country_code_3; #FINAL 3-DIGIT COUNTRY CODE (EG: USA)
print $currency_code; #FINAL 3-DIGIT CURRENCY CODE (EG: USD)

#If you want to display the currency's symbol in HTML:
$symbol_html = "";
@symbol_characters = split(',', $symbol_unicode);
foreach $symbol_characters(@symbol_characters) {
    $symbol_html = $symbol_html."&#".$symbol_characters.";";
    }
print $symbol_html; #FINAL SYMBOL HTML (EG: $)

#If you want to display an image of the flag in HTML:
$flag_image = "<img src='".$flag_url."' />";
print $flag_image; #FINAL FLAG IMAGE

Free 14-Day Trial

Sign Up Now!

Get started right away!