Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

Making perl getc work as advertised

Go to solution
Matt Hearn
Regular Advisor

Making perl getc work as advertised

I'm trying to figure out how to get perl "getc" to work in a way that you don't have to hit "enter" to get it to read the character.

Right now, I can type a letter and then hit "enter" and it reads the letter, but I want to make a menu script that won't require the "enter" input, just read the letter when pressed and continue.

I'm told that there are stty settings that can make this happen, but I can't find any documentation that tells me what they might need to be on an HP-UX server.

I'm not even sure if what I want to do is possible with perl, but my perl manual seems to indicate that it is if the stty settings are right.

Has anyone been able to do this? Thanks!
Rodney Hills
Honored Contributor

Re: Making perl getc work as advertised

stty -raw

is probabily what you are looking for.


-- Rod Hills
There be dragons...
Matt Hearn
Regular Advisor

Re: Making perl getc work as advertised

Almost right; it actually turned out to be "stty raw" (instead of "stty -raw"). That fixed it!

Thank you!!!
Vali Ticau
Occasional Visitor

Re: Making perl getc work as advertised

This is a FAQ, please run:

perldoc -q keyboard
A. Clay Stephenson
Acclaimed Contributor

Re: Making perl getc work as advertised

stty raw will do this but a better approach would be to use one of the Curses modules so that keystrokes like Arrow-Keys (which vary with TERM) can be recognized independent of the terminal type.
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor

Re: Making perl getc work as advertised

using stty commands is not very portable in Perl scripting. If you're only using it on a single machine, don't use redirection (input from files instead of keyboard) or stick it in batchjobs, you might be OK, otherwise I'd suggest looking for more portable ways, like Term::ReadLine, Term::ReadLine::Gnu, Term::Cap, Term::GetKey, readline, and probably many others available on CPAN

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn