root/misc/currency

Revision 1958 (checked in by miyagawa, 13 years ago)

added Number::Format

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Getopt::Long;
5 use Finance::Currency::Convert::Yahoo;
6 use Number::Format;
7
8 my $to   = "JPY";
9 GetOptions('--to=s', \$to);
10
11 no warnings 'uninitialized';
12 my $stuff = join ' ', @ARGV;
13 my($quant, $currency) = split /\s+/, $stuff;
14 if ($quant =~ /^\w{3}$/ && $currency =~ /^[\d\,\.]+$/) {
15     ($quant, $currency) = ($currency, $quant);
16 }
17
18 if ($currency !~ /^\w{3}$/) {
19     die "Unknown currency: $currency\n";
20 }
21
22 $quant =~ tr/,//d;
23
24 $currency = uc($currency);
25 $to       = uc($to);
26
27 my $how = Finance::Currency::Convert::Yahoo::convert($quant, $currency, $to) or exit;
28 print comma($quant), " $currency = ", comma($how), " $to\n";
29
30 sub comma {
31     Number::Format->new->format_number($_[0]);
32 }
Note: See TracBrowser for help on using the browser.