#!/usr/bin/perl # Script for doing 'off the cuff' calculations from the command line # # if brackets, i.e. "(" and ")", are needed, then the string must # be in quotes. # # USAGE: # # $calc 4 + 3^2 # OR # $calc 4 + 3 ** 2 # OR # $calc "(4 + 3**2)" # # etc. # # RSM || 02Jan07 # ramzi@dal.ca $g = $ARGV[0]; $i = 1; while ($i < scalar(@ARGV)) { $g = $g . $ARGV[$i]; $i++; } $g =~ s/\^/**/g; print eval($g) . "\n";