[ic] Interchange Howto: Exchange Rate UserTag - REPOSTED FIXED

Paul Rogers paul at btsonline.co.uk
Wed Mar 16 09:26:48 EST 2005

I'm reposting the UserTag code as it got accidently messed up
in the first post. Apologies to anyone who's had problems using it.

I've had some questions re updating locale db with this tag, so
I've put an example page on my site for anyone who's interested.

Would welcome any comments on alternative update methods and/or
automating updates. Feel free to e-mail or find me on the IC
IRC chatroom.

Paul Rogers
Interchange Consultant
Business Technology Solutions
Interchange Resource Pages

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 USD or EUR
# and returns the rate to IC. Default currency to convert from is GBP.
# Usage: [exchange-rate ###] ### = 3 letter international currency code (EUR
or USD)
# Copyright 2005 Paul Rogers - Business Technology Solutions
# Updates and support available at:
# http://www.btsonline.co.uk/ic
# Note: Please leave this copyright message intact if you wish to use this
UserTag  exchange-rate  Order currency
UserTag  exchange-rate  PosNumber 1
UserTag exchange-rate Routine <<EOR
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.7.3 - Release Date: 15/03/05

More information about the interchange-users mailing list