I just stumbled upon something I have searched for a couple of times without success. It involves how to clear a screen within an interactive Perl program.
It might seem an obvious thing, but believe me, for a novice, who has shaky Unix knowledge in the first place, this is a useful ability: to be able to wipe the screen in simple interactive programs. It might even be educational-- there are all kinds of other system commands they might think to learn and employ.
All that said, this is my draft of a Q & A, with comments welcome, and with suggestions for where it might go even more welcome. Maybe we could make a novice/misc Q & A section? And what about making a table somewhere in the Q & A or Tutorials section, of common systems commands and what they do?
How do I clear the screen?
Sometimes, in a program, you want all previous inputs to disappear, for aesthetic or other reasons. When you want this to happen, add this line to your program at the appropriate spot:
system "clear";
An example follows: part of a program to interactively quiz a child on his times tables. Note text in <> is pseudocode, except for "<STDIN>":
Note that I was going to post this as a question in SoPW, until I stumbled across another system command, and wondered what would happen if I substituted "clear" where that other command was. But I remember a time when I didn't know "clear" was a Unix command. Hence this little Q & A. Thanks in advance for your comments.while (my $exit = 0) { <generate question variables randomly and calculate solution> print "$mult1 * $mult2 = ?\n"; chomp ($guess = <STDIN>); <test whether $guess = $solution; if so> print "Good job! Want to play again? (Y/N)\n"; <test answer here; if Y, then> system "clear"; } <program loops back and pick another pair of numbers and caculates +their product>
NovMonk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC: Draft Q & A: How to clear the screen in a perl program
by Fletch (Bishop) on Jul 18, 2006 at 19:06 UTC | |
|
Re: RFC: Draft Q & A: How to clear the screen in a perl program
by gellyfish (Monsignor) on Jul 18, 2006 at 19:07 UTC | |
|
Re: RFC: Draft Q & A: How to clear the screen in a perl program
by ysth (Canon) on Jul 18, 2006 at 23:32 UTC | |
|
Re: RFC: Draft Q & A: How to clear the screen in a perl program
by NovMonk (Chaplain) on Jul 20, 2006 at 12:09 UTC | |
| |
|
Re: RFC: Draft Q & A: How to clear the screen in a perl program
by Anonymous Monk on Jul 19, 2006 at 19:02 UTC |