|Just another Perl shrine|
RFC: Draft Q & A: How to clear the screen in a perl programby NovMonk (Chaplain)
|on Jul 18, 2006 at 18:38 UTC||Need Help??|
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:
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.