Re: Making perl getc work as advertised (231 Views)
Reply
Regular Advisor
Matt Hearn
Posts: 230
Registered: ‎03-12-2002
Message 1 of 6 (231 Views)
Accepted Solution

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!
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 2 of 6 (231 Views)

Re: Making perl getc work as advertised

stty -raw

is probabily what you are looking for.

HTH

-- Rod Hills
There be dragons...
Regular Advisor
Matt Hearn
Posts: 230
Registered: ‎03-12-2002
Message 3 of 6 (231 Views)

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
Vali Ticau
Posts: 4
Registered: ‎10-14-2004
Message 4 of 6 (231 Views)

Re: Making perl getc work as advertised

This is a FAQ, please run:

perldoc -q keyboard
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 5 of 6 (231 Views)

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.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,188
Registered: ‎10-13-1997
Message 6 of 6 (231 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.