in reply to Emulating UNIX 'top' on AIX

Is the problem that <> blocks? Try Term::ReadKey

By the way, <> does not necessarily read from STDIN. <STDIN> does.

Replies are listed 'Best First'.
Re^2: Emulating UNIX 'top' on AIX
by Transient (Hermit) on May 02, 2005 at 15:59 UTC
    Well, I got around the blocking issue. I used waitpid $pid, WNOHANG and I can now read in from STDIN.

    The next issue is to read character by character instead of line by line. Is there any pure Perl way to do this?

      No. <FILE>, getc, read and sysread all block until a newline is read (even if they only return one character at a time). That's why I mentioned Term::ReadKey.

      Well, maybe you can do something with PerlIO. I don't know anything about that.

        the Perl getc docs have references to system calls using stty icanon which seem to emulate reading character by character. While not the solution I would most like to use, it does serve its purpose :)
      Ok, found some stuff about getc from the docs... using that seems to work!

      I'll post the code at the end for critique and future use.