Well, I may have found The Right Way to accomplish my timed reads. Term::ReadKey has a ReadKey() function (exported by default) that accepts a timeout and returns a first keystroke or undef if the timeout occurs. So I can write a timed_read() routine around it which goes ahead and reads until $/ with <>, prepends the first character, and moves on.
I've already got a routine with IO::Select, but it appears to not be working sometimes, and I don't know why. Sometimes it times out when the input should be there. I'll implement the ReadKey() version and see if it makes a difference.
Of course, when I discovered ReadKey() gave me what I needed, I looked to see how it was implemented. The answer was that the author checks far more things about the system than I knew existed and then eval's one of many ReadKey() definitions into existence. Wow! Talk about a motivator for calling a module instead of cut-and-paste.
I'm doing all this over sockets, through inetd, just to be difficult, you know. :) One of the first things I checked with Term::ReadKey was if it would work with a socket. (Or, at least, a socket that looks like a STDIN.) BTW, I absolutely love the Net::DummyInetd module, removed from the libnet distribution, but still available unless the author has done housekeeping. (Like Matt Sergeant, who recently removed the older, pure-Perl version of Time::Object from CPAN before last Friday when I really needed it all of a sudden. I forgive you, Matt! :) ) DummyInetd.pm can let you write your programs for inetd without having to set up inetd yourself. (I let the sysadmins do that; they always want to keep control, anyway.)
Re:user run inetd
jdavidb on 2002-05-08T14:00:33
BTW, if your sysadmin notices two copies of inetd running, she may start getting confused, so it's probably an idea to let her know what you're doing even though it's perfectly reasonable.
Yep. That's another advantage of the wrapper script.
:) I think I did the personally run inetd a couple of years back, but the wrapper I've written with the DummyInetd module makes it easier because I don't have to do any setup. It's just
./inetd path/to/program. Also, don't you still have to configure /etc/services with inetd even if you're not root? It's been awhile, so I don't remember.