/projects/gcalc last modified 32.925 days ago

gcalc.pl: Standalone Google Calculator

gcalc.pl is a Perl script that provides a command-line interface to Google's calculator feature. For each expression given, the script will query Google and return the result. It can be run in both one-shot and interactive modes and also has readline support to provide a history of typed expressions.

Examples

% gcalc -h
gcalc.pl, version 1.0
usage: gcalc [options] [expression]
options:
  -h, --help             display this help
  -i, --interactive      interactive mode (default if no expression is given)
 
examples:
  $ gcalc '2+2'
  2 + 2 = 4
  $ gcalc one meter in light years
  one meter = 1.05702341 x 10^-16 light years
 
more: http://www.google.com/help/features.html#calculator
% gcalc
gcalc.pl 1.0: Google Calculator
type 'help' for help
>> one furlong in meters
one furlong = 201.16800 meters
>> 68 f in c
68 degrees Fahrenheit = 20 degrees Celsius
>> q
%

Download

Download from labs.*: gcalc.pl

Installation

Unix-based Operating Systems

Perl must be installed. For the readline support to work, a Term::ReadLine::* Perl module is needed. If you are using GNU/Linux, install the Term::ReadLine::Gnu package with the CPAN installer.

A good way to install gcalc.pl is to make a bin directory in your home directory, copy the script there, and add ~/bin to your $PATH. You may optionally wish to remove the .pl extension or add a symlink like so:

ln -s ~/bin/gcalc.pl ~/bin/gcalc

Remember to give the file execution permissions with:

chmod +x gcalc.pl

Windows-based Operating Systems

Windows-based operating systems require ActivePerl. On a default install of ActivePerl, gcalc.pl appears to work, albeit with some warnings. It is easiest to place the script into a directory that is in your %PATH%. Type:

echo %PATH%

at a command prompt to see which directories are included.