Log in

07 March 2009 @ 06:38 pm
Google calc on the command line  
At some point a wrote a currency calculator. It downloaded a list of current exchange rates from a bank, somewhere. The draw back was that it could only convert to and from NOKs.
I decided to give it a brush-up. After tinkering a bit with it I realized that google has quite a nice exchange rate calculator in its generic calculator. I wanted something I could operate from the command line so I went a found the WWW::Google::Calculator module on CPAN. On my ubuntu laptop this module is packaged in libwww-google-calculator-perl. The module does everything I needed, really, I just needed to to call it. Anyway, here is how it works:

perbu@thimk:~$ googlec 100 USD in EURO
100 U.S. dollars = 78.976465 Euros

The code is suprisingly simple:

use WWW::Google::Calculator;
my $calc = WWW::Google::Calculator->new;
print $calc->calc(join(' ',@ARGV)),"\n";

As a bonus it does all other sort of calculations:
perbu@thimk:~$ googlec "5*9+(sqrt 10)^3"
(5 * 9) + (sqrt(10)^3) = 76.6227766

Cool, eh?
Tags: ,
Current Mood: amusedamused
fibonacciprower on October 19th, 2010 06:37 am (UTC)
Doesn't work anymore.

I suspect the root of the problem is the WWW::Google::Calculator module - but I don't know anything about Perl to test it.