Just hadda' check, following my own suggestion above. Installed requisite modules, tweaked code and came up with this:
Execution:#!/usr/local/bin/perl use 5.016; use warnings; # 1071094 use utf8; use Locale::Currency; use File::Basename; use Cache::FileCache; use Finance::Quote; use POSIX; say "FOO: ". get_price("CHF","EUR","50") . "\n"; sub get_price { my ($currency_from,$currency_to,$amount) = @_; 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"); say "\$ratio: $ratio \t \$currency_from $currency_from \t \$currency_t +o: $currency_to"; $ratio = $quote->currency($currency_from, $currency_to) unless defined $ratio; say "\$ratio: $ratio, \t \$currency_from $currency_from, \t \$currency +_to: $currency_to"; die "sorry, cannot convert from $currency_from to $currency_to\n" unless defined $ratio; $cache->set("$currency_from:$currency_to", $ratio); return $amount * $ratio }
C:\> 1071094.pl Use of uninitialized value $ENV{"HOME"} in concatenation (.) or string + at D:\_Perl_\PMonks\1071094.pl line 19. $ratio: 0.8113 $currency_from CHF $currency_to: EUR $ratio: 0.8113, $currency_from CHF, $currency_to: EUR FOO: 40.565
The 'uninitialized' isn't exactly surprising; nor does it appear to be crucial. The rest is plausible, but of undetermined correct-ness.
In reply to Re: Finance::Quote giving weird error
by ww
in thread Finance::Quote giving weird error
by ultranerds
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |