Perl FAQ 4.32: How can I get input from the keyboard without it echoing to the

Perl FAQ 4.32

How can I get input from the keyboard without it echoing to the

screen?

Terminal echoing is generally handled directly by the shell. Therefore, there is no direct way in perl to turn echoing on and off. However, you can call the command "stty [-]echo". The following will allow you to accept input without it being echoed to the screen, for example as a way to accept passwords (error checking deleted for brevity):

    print "Please enter your password: '';
    system("stty -echo");
    chop($password=);
    print "\n";
    system("stty echo");
    

Again, under perl 5, you can use Curses and call &Curses::noecho() and &Curses::echo() to turn echoing off and on. Or, there's always the ReadKey extension.


Other resources at this site: