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.

In reply to Re: Finance::Quote giving weird error by ww
in thread Finance::Quote giving weird error by ultranerds

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.