For those that don't have any silly "no modules" restrictions, this problem could be solved by using the Term::ReadKey module. For those that insist on re-inventing the wheel, reading the code in this module will probably help you along your way. Remember that even though you may (for whatever reason) not be able to use a module with your project, that doesn't prevent you from downloading it and reading through the code to see how they do it.

The short answer: check out the documentation for getc, which is Perl's implementation of the standard C function by the same name. Update: I highly recommend going with the FAQ links mentioned above, as there are some caveats with using getc on terminals.

If you need to be monitoring several input streams at once for data, and thus need to use select, that is a very weighty topic. See the documentation for IO::Select.. There are probably other tutorials floating around, but I doubt you're going to get a thorough lesson on select here. Good luck.


In reply to Re: select? by Fastolfe
in thread select? by BooK

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.