[ic] Interchange Howto: Exchange Rate UserTag

Paul Rogers paul at btsnet.co.uk
Wed Mar 9 09:35:50 EST 2005

Hi all,

I've just finished a new [exchange-rate] UserTag for Interchange which will
fetch, parse and display
currency exchange rates and which I hope someone may find useful.

The tag allows currency exchange rates to be fetched for Euros and US
Dollars, with UK Pounds as the base
currency, but can be adapted for any currencies. It can be used anywhere in
your pages as follows:

[exchange-rate USD] or [exchange-rate EUR]

To make the tag, copy the code below into a file called 'exchange_rate.tag'
and place into the UserTag
directory, then restart Interchange server:

------------------------- BEGIN
CODE -----------------------------------------

# [exchange-rate]
# This tag gets the latest exchange rate from Yahoo Finance for EUR and USD
# GBP and returns the rate to IC.
# Usage: [exchange-rate ###]
# Copyright 2005 Business Technology Solutions
# Updates and support available at:
# http://www.btsonline.co.uk/ic
# Please leave this copyright message intact if you
# wish to use this tag.
UserTag exchange-rate Order currency
UserTag exchange-rate PosNumber 1
UserTag exchange-rate Routine < sub {

my ($currency) = @_;
my $url;

if ($currency eq 'EUR') {

$url =
else {

$url =
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;
$content =~ /(d.d{2,3})(......)/;
return $1;
# $Session->{mv_perl_result} = $1;

------------------------------------ END
CODE -------------------------------------------

The base currency can be changed from UK Pounds and set to any currency
simply by changing the
'from=###' part of the lookup URL's to any 3 letter international currency

The tag can also be easily adapted to convert to other currencies simply by
changing the 'to=###'
part of lookup URL's as above.

Since there is a slight delay between fetching the URL and parsing it before
returning the exchange
rate. Therefore it's perhaps not recommended to use this tag in frequently
used pages.

If you need to display the currency exchange rate in your pages or use it in
your code to determine prices,
a better solution is to use the exchange-rate tag to update your locale
table, and then query the locale
table to get the data from there. A simple method for achieving this
detailed on my website at the url below
for those interested.

Paul Rogers
Interchange Consultant
Business Technology Solutions
Interchange Resource Pages

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.6.4 - Release Date: 07/03/05

More information about the interchange-users mailing list