root/misc/currency

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

use Pod::Usage

  • 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 }
19
20 if ($currency !~ /^\w{3}$/) {
21     pod2usage("Unknown currency: $currency\n");
22 }
23
24 $quant =~ tr/,//d;
25
26 $currency = uc($currency);
27 $to       = uc($to);
28
29 my $how = Finance::Currency::Convert::Yahoo::convert($quant, $currency, $to) or exit;
30 print comma($quant), " $currency = ", comma($how), " $to\n";
31
32 sub comma {
33     Number::Format->new->format_number($_[0]);
34 }
35
36 __END__
37
38 =head1 NAME
39
40 currency - Convert currency from one to another
41
42 =head1 SYNOPSIS
43
44   currency 100 USD
45   currency -t GBP 1000 THB
46
47 =cut
Note: See TracBrowser for help on using the browser.