perbu (perbu) wrote,

  • Mood:

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: google, perl

  • I've lost my tin foil hat!

    Google makes a lot of money and I believe 99% comes from adsense. When you make such an enourmous amount of cash you would be stupid not to invest in…

  • Sun - the dot in

    Sorry about the lame pun. I couldn't resist. How will the Sun acquisition affect Redpill Linpro and it's products? It's not quite clear yet, but I…

  • ext4 and the Jaunty Jackalope

    I've been longing for ext4 for a long time now. ext3 has a really broken implementation of fsync(2). Each fsync() turns into a sync(). If there is…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment