use strict; use warnings; use Locale::Currency; use File::Basename; use Cache::FileCache; use Finance::Quote; die "usage: $0 amount currency_from currency_to\n" unless @ARGV == 3; my $amount = shift @ARGV; my ($currency_from, $currency_to) = map { uc } @ARGV; for my $code ($currency_from, $currency_to) { die "sorry, currency $code not in ISO 4217\n" unless defined code2currency($code); } my ($filename) = fileparse($0, '.pl'); my $cache = Cache::FileCache->new({ cache_root => "$ENV{HOME}/.$filename", default_expires_in => '1 day', }); my $quote = Finance::Quote->new(); my $ratio = $cache->get("$currency_from:$currency_to"); $ratio = $quote->currency($currency_from, $currency_to) unless defined $ratio; die "sorry, cannot convert from $currency_from to $currency_to\n" unless defined $ratio; $cache->set("$currency_from:$currency_to", $ratio); print "$amount $currency_from = ", $amount * $ratio, " $currency_to\n";