Raymond Wan wrote:

Hi Greg,


Greg wrote:
I have a script, where a user can choose between different options (add user (U), add item (I), search (S)). I want the user to hit either U, I or S. However, right now, he needs to hit return as well. Is there a way to get input without hitting return?


Take a look at http://perldoc.perl.org/functions/getc.html -- in particular, not this page, but the module it points you to in the example...

Ray



Hi,

thank you for your quick responses. It works with Term::ReadKey.

#!user/bin/perl

use strict;
use warnings;
use Term::ReadKey;

ReadMode 4;
my $key;

print "Enter A, B, C\n";

 while (not defined ($key = ReadKey(-1))) {
        }
ReadMode 0;

if ($key eq "A") {
        print "A\n";
} elsif ($key eq "B") {
        print "B\n";
} elsif ($key eq "C") {
        print "C\n";
} else {
        print "Wrong input\n";
        }       
        
Best regards,

Greg

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to