Hi Monks, I have written some code where I am using threads - 4 threads to be precise. I am printing some stuff in all these threads and as expected, when I execute the program, all print statements are coming up one after the other. This is fine as long as I am printing output.

However, I also need to get inputs from users across all 4 threads. Because these input prompts (and print statements) come up at almost the same time, the user is confused as to what input (s)he is trying to enter... and most of the times, the wrong input is entered because of this "mass" of text on the screen.

To give you an idea what my screen looks like, see this:

T1-Enter Option: T3-Would you like to continue (y/n): T2-T4Press any k +ey to exit-Please choose an item from the menu:

Basically, its printing everything in one shot. I tried using newlines, etc. to separate these input prompts, but it didn't help much.

Here's my question: Is there any way we can have the screen clear & refresh every N seconds and each time it refreshes, it prints the stuff relevant to one thread only? This way, I am doing a cyclic refresh of screens where each thread displays only its input prompt during its' N seconds of display - and after input has been given, each thread continues to show the execution results / print statements relevant to its own context.

So here's what my program would look like when print statements and input prompts are displayed one after the other

Screen1/Thread1:T1-Enter Option: [wait 10s ]

Screen2/Thread2:T2-Press any key to exit [wait 10s]

Screen3/Thread3:T3-Would you like to continue (y/n):[wait 10s]

Screen4/Thread4:T4-Please choose an item from the menu:[wait 10s]

...

...

...

...

keep rotating these screens until the program / threads finish their work...


In reply to Controlling display of print command by vishi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.