alexm's Journal http://use.perl.org/~alexm/journal/ alexm's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:47:25+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 alexm's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~alexm/journal/ Using up-to-date currency conversion rates http://use.perl.org/~alexm/journal/37365?from=rss <p>A friend of mine is living this year in the USA, and she asked me how to program with Perl some unit conversions. The currency conversion is volatile since the ratio changes a lot, so I came up with this:</p><blockquote><div><p> <tt>use strict;<br>use warnings;<br> <br>use File::Basename;<br>use Cache::FileCache;<br>use Finance::Quote;<br> <br>die "usage: $0 amount currency_from currency_to\n"<br>&nbsp; &nbsp; unless @ARGV == 3;<br> <br>my $amount = shift @ARGV;<br> <br>my ($currency_from, $currency_to) = map { uc } @ARGV;<br> <br>my ($filename) = fileparse($0, '.pl');<br> <br>my $cache = Cache::FileCache-&gt;new({<br>&nbsp; &nbsp; cache_root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&gt; "$ENV{HOME}/.$filename",<br>&nbsp; &nbsp; default_expires_in =&gt; '1 day',<br>});<br> <br>my $quote = Finance::Quote-&gt;new();<br> <br>my $ratio = $cache-&gt;get("$currency_from:$currency_to");<br> <br>$ratio = $quote-&gt;currency($currency_from, $currency_to)<br>&nbsp; &nbsp; unless defined $ratio;<br> <br>die "sorry, cannot convert from $currency_from to $currency_to\n"<br>&nbsp; &nbsp; unless defined $ratio;<br> <br>$cache-&gt;set("$currency_from:$currency_to", $ratio);<br>print "$amount $currency_from = ", $amount * $ratio, " $currency_to\n";</tt></p></div> </blockquote><p>She liked it, and so do I because it's so simple that it doesn't need comments at all. Just try:</p><blockquote><div><p> <tt>$ perl exchange.pl 100 usd eur<br>100 USD = 70.22 EUR</tt></p></div> </blockquote> alexm 2008-09-05T17:42:02+00:00 journal Padre packages available for Ubuntu http://use.perl.org/~alexm/journal/37169?from=rss <p>I've been busy since last weekend trying to package <a href="http://search.cpan.org/dist/Padre">Padre</a> for Ubuntu Hardy, and <a href="https://launchpad.net/~alex.muntada/+archive">here it is</a>. The sources are <a href="https://code.launchpad.net/~alex.muntada">available in Launchpad</a>, too.</p><p>This is how you can set it up and install it:</p><ol> <li>Add my PPA sources in APT:<blockquote><div><p> <tt>$ sudo vi<nobr> <wbr></nobr>/etc/apt/sources.list<br>$ tail -3<nobr> <wbr></nobr>/etc/apt/sources.list<br># alexm<br>deb http://ppa.launchpad.net/alex.muntada/ubuntu hardy main<br>deb-src http://ppa.launchpad.net/alex.muntada/ubuntu hardy main</tt></p></div> </blockquote></li><li>Add my GPG signature to APT:<blockquote><div><p> <tt>$ wget 'http://keyserver.ubuntu.com:11371/pks/lookup?op=get&amp;search=0x2DDC42192DF36811' -O- | sudo apt-key add -</tt></p></div> </blockquote></li><li>Update APT:<blockquote><div><p> <tt>$ sudo apt-get update</tt></p></div> </blockquote></li><li>Install Padre:<blockquote><div><p> <tt>$ sudo apt-get intall libpadre-perl</tt></p></div> </blockquote></li></ol><p>This is the first time I manage to build some Perl packages. I had been playing with <code>dh-make-perl</code> in the past, but didn't know much about Debian packaging (not that I know much more now, anyway), but this time I was more motivated. Next step is trying to get them in Debian, so Ubuntu (and others) can make the modules officially part of next releases.</p> alexm 2008-08-13T08:18:25+00:00 journal