qazwart has asked for the wisdom of the Perl Monks concerning the following question:
The real problem was my code in the previous section.
I've found the "Term::ReadKey" module and did a small little test:
Works like a charm! Now, I apply this same technique to my program:#! /usr/bin/env perl use strict; use warnings; use Term::ReadKey; ReadMode "raw"; my $key = ReadKey(0); ReadMode "restore"; print "Backspace detected!\n" if ($key eq "^H"); my $foo = <STDIN>; print "ASCII Code Value = " . ord($key) . "\n"; print "Complete Answer = " . $key . $foo . "\n"; print "You typed a \"$key\"\n";
No good! When I print the value of "$key", it shows the correct ASCII value, but it doesn't seem to read control characters, so it simply ignores "Ctrl-H" presses.print "\n\nANSWER"; if (defined($default)) { print " [Default = $default]"; } print ": "; ReadMode "raw"; my $key = ReadKey(0); ReadMode "restore"; if ($key eq "^H") { #Help Mode! $showHelpFlag = 1; redo; } chomp($answer = $key . <STDIN>);
So, why does the test program work, but the same code in my more complex program doesn't? BTW, the code is in a part where I redefined the package name. I'm making a feeble attempting to do object oriented programming. Would this do anything?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading Single Character Input with Term::ReadKey
by BrowserUk (Patriarch) on Apr 17, 2007 at 18:20 UTC | |
by Fletch (Bishop) on Apr 17, 2007 at 18:25 UTC | |
by BrowserUk (Patriarch) on Apr 17, 2007 at 18:52 UTC | |
|
Re: Reading Single Character Input with Term::ReadKey
by shmem (Chancellor) on Apr 17, 2007 at 18:16 UTC |