while( true )
{
print "gimme: ";
$line=<>;
$value=eval( $line );
$error=$@;
if( $error ne "" ){ print $error; }else{ print "$value\n"; }
}
The reader is respectfully invited to select and copy the program, and to paste it into an empty file, and to save the file for use with the Perl language. Actually, it is possible and probable that the reader has already invented this program herself.
All I want is to start the program and see the prompt
gimme:and type in a Perl expression that I wish to be evaluated
gimme: sin(.1)and push the “Enter” key. In this instance the program will print
0.0998334166468282Actually, the program does not prompt in red. I just did that in the present file for easier reading. The word “gimme” is a two-syllable contraction in American English for “give to me.” The “g” has a hard sound, not soft. The user can of course change the program to use a more professional-looking prompt, or a prompt in a different language.
The program is not restricted to expressions. Any Perl statements are permitted, but they must not take more than one line each. Here is an example:
gimme: $x=1.23 gimme: $y=(exp($x)+exp(-$x))/2 gimme: sqrt($y)It is permissible to put more than one statement or expression on a line, but the semicolon separator must then be used. Please do not use the “my” modifier unless a function is being built.
The easiest way to leave the program is to use
gimme: exit
at dot
smtw2gh toadmail com
This file is most recently revised on 25 June 2008.