updates @ m.blog

Google Calculator From Command Line

I used to frequently use bc or units from the command line to handle any quick calculation needs, but the handiness of google calculator (as documented in many other places) has largely displaced them. Who wants to bother to open a web browser for results though? So I made a quick perl hack to grab it from command line, example usage:

$ gcalc 2+4/6*8
2 + ((4 / 6) * 8) = 7.33333333
$ gcalc "12 * 12oz. in gallons"
12 * 12 US fluid ounces = 1.12500 US gallons
$ gcalc the speed of light in km/fortnight
the speed of light = 3.62628957 x 10^(11) kilometers / fortnight
$ gcalc the answer to life, the universe, and everything
the answer to life, the universe, and everything = 42

Download the perl script (916 bytes), share and enjoy. I find it handy to have access to this in IRC, so there is also a version as a xchat plugin.

Yes, I know that you’re supposed to use the Google XML-API rather than screen-scraping, unfortunately the API does not return any Calculator results, so scraping appears to be the only way for now.

Comments