in reply to Finance::Quote giving weird error

Awright.... ;-)

Just hadda' check, following my own suggestion above. Installed requisite modules, tweaked code and came up with this:

#!/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 }
Execution:
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.

If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.

Replies are listed 'Best First'.
Re^2: Finance::Quote giving weird error
by ultranerds (Hermit) on Jan 18, 2014 at 15:13 UTC
    Thanks for the reply :) I think I was actually just being a dumb arse!
    [Sat Jan 18 16:11:05 2014] test.cgi: Illegal division by zero at /usr/ +lib/perl5/site_perl/5.8.8/Finance/Quote/IndiaMutual.pm line 27. [Sat Jan 18 16:11:05 2014] test.cgi: Compilation failed in require at +(eval 34) line 1. [Sat Jan 18 16:11:05 2014] test.cgi: BEGIN failed--compilation aborted + at (eval 34) line 1. [Sat Jan 18 16:11:05 2014] test.cgi: at test.cgi line 45 FOO: 40.565
    The "FOO" bit with the price prints out just fine... so as you said, the debugging coming out in the SSH terminal shouldn't affect it . So in fact, it was actually running just fine... doh!