23
Oct
20:55 2009

Perl script for converting between currencies

Hello there dear readers,

I’ve been working on a little command line utility this afternoon to convert between different currencies google style. Instead of googling “10 USD in EUR” every time, you can simply type the same in the command line and get the result straight from your terminal.

My intention was originally to make this script into a Quicksilver utility. It could easily be done by having an applescript supply the data to  but unfortunately Applescript seems broken in Quicksilver on Snow Leopard and I still haven’t had the chance to try to fix it.

In case this one caught you by surprise – yes, there’s actually a version of Qucksilver that works fine with Snow Leopard.

Installing this script

  1. Install Finance::Currency::Convert::Yahoo. To do this:
    1. Start cpan
    2. Type: install Finance::Currency::Convert::Yahoo
  2. Put the script somewhere you like
  3. Make sure it’s executable (chmod +x ./currency.pl)
  4. Done!

Using this script

Couldn’t be any easier:

% ./currency.pl 100 USD in EUR
66.58 EUR

And that’s it!

It also takes other forms of input. For instance:

  • “10USD in GBP”
  • “USD10 in GBP”
  • “USD 10 JPY”
  • “$20.10 in cny” (keep in mind that you will need to escape that dollar sign or the shell might think it needs to do something with it)

The basic rule of thumb is that the first currency is the source, the second is the target and that a number is the value in the source currency. You may only supply ONE of each.

Note: I added a substitution from “NIS” (New Israeli Shekel) to ILS (Israeli Shekel). Yahoo prefers the code ILS while I prefer NIS, no biggie.

License

Public domain, baby.

Getting the script

Save this file. Then see above instructions.

Changelog

Leave a Reply

This is your chance to voice your opinion! Type it down below and submit it. As long as it's not abusive, rude or annoying it will likely be approved.

Avatars are generated by the gravatar service and are based on your email address. To change them, head to gravatar.com and register.

The following tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>