2011-03-07 72 views
3

你们会怎么弄出只有国家代码的货币?理想情况下,在Perl中,但我认为任何其他语言解决方案都很容易移植。如何按国家获取货币?

感谢

+0

我添加了“perl”的标签,以增加潜在观众。总是看到你添加了一个(相关的)语言或平台标签,以便你的问题被订阅了该标签的人看到 – 2011-03-07 12:52:20

回答

2

它看起来像Locale::Object::Currency从CPAN包含了你所需要的。但是,自2007年以来似乎没有更新过。

#!/usr/bin/perl 

use Locale::Object::Currency; 
use Data::Dumper; 
use strict; 
use warnings; 

my $bucks = Locale::Object::Currency->new(country_code => 'us'); 
print Dumper($bucks->symbol, $bucks->code, $bucks->name); # etc.. 

#print Dumper $bucks; # don't do this in production; use the method interface; 
         # but it does appear to have the info you need. 
-1

你可以尝试找到一个为你做这个的web服务。例如,webservicex.net提供了一个GetCurrencyByCountry操作。

另一种方法是从某处的国家/货币映射保存到一个文件,然后将它们加载到你的程序的地图。

+0

不幸的是'webservicex'已经为此目的过时的信息。它至少有墨西哥,罗马尼亚和土耳其货币的旧代码。 – hippietrail 2012-08-01 21:09:14