If you are on a Unix platform, you can open the file descriptor /dev/tty (or use IO::Pty ).
A good example of working with tty is given in the example "Testing the program Interactively": http://pleac.sourceforge.net/pleac_perl/userinterfaces.html
You should also consider entering a password through Term::ReadKey (described in perlfaq8 ) - I think this can be tied to TTY instead of STDIO, but I'm not sure. If this is not the case, use the TTY + Term :: ReadKey solution indicated at the end of this SO response from brian d foy .
Here is an example.
This is not the best style (does not use the 3-arg form open , and also uses lexical file descriptors) , but it should work.
use autodie; # Yay! No "or die '' " use Term::ReadKey; open(TTYOUT, ">/dev/tty"); print TTYOUT "Password?: "; close(TTYOUT); open(TTY, "</dev/tty"); ReadMode('noecho'); $password = ReadLine(0, *TTY);
DVK
source share