Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Making perl getc work as advertised

SOLVED
Go to Solution
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!
5 REPLIES
Honored Contributor Honored Contributor

Re: Making perl getc work as advertised

stty -raw

is probabily what you are looking for.

HTH

-- Rod Hills
There be dragons...
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!!!
Occasional Visitor

Re: Making perl getc work as advertised

This is a FAQ, please run:

perldoc -q keyboard
Acclaimed Contributor 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.
Highlighted
Honored Contributor 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

http://search.cpan.org/search?query=Term%3A%3A&mode=all

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