#!/usr/bin/perl #$Id: calcme,v 1.4 2001/10/04 18:00:57 mstorti Exp $ $input=shift; # require "$ENV{'HOME'}/perl/math.pl"; if ($input eq "-h") { print <<'EOM'; CALCME: a simple (Perl based) line calculator usage : * Compute an expression (remember to enclose in quotes or double quotes in order to avoid shell expansion ) $ calc * Interactive use: $ calc > > ... Can define variables as in; > $pi=atan(1,0)*2 > $pi=atan2(1,0)*2 3.14159265358979 > $e=exp(1) 2.71828182845905 > $a=$pi*$e**2 23.2134043573634 > * Get help (prints this message): $ calc -u EOM goto EXIT; } @ans=(); do {print "> ",eval $input,"\n"; goto EXIT; } if $input; print "> "; while () { print $ans=eval(),"\n> "; unshift @ans,$ans; } EXIT: ;