megaurav2002 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Is it possible to read an input that is not followed by <enter>. Example: If a user enters "A", my program should be immediately able to store "A" and process accordingly rather than waiting for the <enter> key. Any function to do this ??

Thanks a lot
Gaurav
"Wisdom begins in wonder" - Socrates, philosopher

Replies are listed 'Best First'.
Re: Reading Input Question
by ikegami (Patriarch) on Feb 05, 2008 at 03:34 UTC
Re: Reading Input Question
by quester (Vicar) on Feb 05, 2008 at 05:29 UTC
    Not pretty, not efficient, and not even pure Perl, but if you really don't want to use CPAN modules for some reason, look at the example in perlfunc under getc.

      No. getc, read and sysread don't work. They don't return anything before an Enter is received.

      By the way, why did you say getc isn't pretty?

      Update: Ah, you mean in conjunction with stty. Nevermind.

Re: Reading Input Question
by zentara (Cardinal) on Feb 05, 2008 at 14:01 UTC
    This might be of use Readkey with timer using Glib. The problem with Term::Readkey, is it needs a controlling loop, which make interfere with running code in the main block of code. BUT.... if you put the Readkey stuff in a thread, it will work fine, and you can use the main code block to do whatever. I added GLib so you can run timers or filehandles watches.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum