|Perl Monk, Perl Meditation|
Re: Non-blocking reading on STDIN?by betterworld (Curate)
|on Apr 19, 2009 at 10:06 UTC||Need Help??|
I want to create a non-blocking read on STDIN, that means I don't have to enter RETRUN, each characters would show up just after I have enter it on the terminal
I think you mean RETURN. Anyway, the two things you mention are not the same. Blocking mode means that read operations blocks until input is available. Input is available if you have typed either a character or a whole line, depending on the terminal settings. This particular setting is known as "canonical mode". You can test it with the "stty" command, but undoubtedly there CPAN modules to leave and enter canonical mode.
Another thing one should be aware about: For terminal applications, usually STDIN has the same file descriptor as STDOUT. This means that if you set the non-blocking flag for STDIN, it will be set for STDOUT, too. This means that if you print a long buffer to the terminal, it might be truncated and print returns EAGAIN. But as nobody checks the error code when printing to a terminal (e.g. curses doesn't seem to do so), the terminal will at some point display unexpected contents.