good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Calc Helpby Anonymous Monk |
on Aug 19, 2014 at 15:20 UTC ( [id://1097985]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: Write a program called calculate.pl which will operate as a primitive calculator operating on a single number (the 'accumulator') whose value may be modified by user commands. The program should meet the following requirements: When called with arguments, interprets them as names of files containing commands. When called without arguments, reads commands from standard input. You may find it easy or at least entertaining to run the program in this mode. Commands are lines that match one of the following patterns:
The intended effects of those commands can be seen in the following capture of program interaction. User input is EQUALS, CLEAR, PLUS, OVER, TIMES, MINUS. The accumulator starts out undefined.
You can assume that there is exactly one space between the operator and the number in valid commands. You do not have to trap division by zero or warnings about operating on an undefined accumulator. Use subroutines to keep the length of the main program and each of the subroutines below a standard screen (24 lines) at one statement per line. Output a prompt string "> " before each input, like so: calculate.pl dialog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm not planning on proceeding with learning much more Perl, however, I would just like to see how this project can be accomplished for piece of mind. Any help would be greatly appreciated!
Back to
Seekers of Perl Wisdom
|
|