root/misc/currency

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

allow currency USD

  • 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 use Pod::Usage;
8
9 my $to   = "JPY";
10 GetOptions('help|?' => \my $help, '--to=s', \$to);
11 pod2usage(1) if $help;
12
13 no warnings 'uninitialized';
14 my $stuff = join ' ', @ARGV;
15 my($quant, $currency) = split /\s+/, $stuff;
16 if ($quant =~ /^\w{3}$/ && $currency =~ /^[\d\,\.]*$/) {
17     ($quant, $currency) = ($currency, $quant);
18     $quant ||= 1;
19 }
20
21 if ($currency !~ /^\w{3}$/) {
22     pod2usage("Unknown currency: $currency\n");
23 }
24
25 $quant =~ tr/,//d;
26
27 $currency = uc($currency);
28 $to       = uc($to);
29
30 my $how = Finance::Currency::Convert::Yahoo::convert($quant, $currency, $to) or exit;
31 print comma($quant), " $currency = ", comma($how), " $to\n";
32
33 sub comma {
34     Number::Format->new->format_number($_[0]);
35 }
36
37 __END__
38
39 =head1 NAME
40
41 currency - Convert currency from one to another
42
43 =head1 SYNOPSIS
44
45   currency 100 USD
46   currency -t GBP 1000 THB
47
48 =cut
Note: See TracBrowser for help on using the browser.