http://www.perlmonks.org?node_id=590228


in reply to Editing STDIN

You could use Term::InKey, like so:
use Term::InKey; print "password: "; my $password = ReadPassword("*"); print "\nYour password is '$password'\n";

Replies are listed 'Best First'.
Re^2: Editing STDIN
by rodion (Chaplain) on Dec 17, 2006 at 14:27 UTC
    Term::InKey is a good solution to the OP question, especially if he really does want to be able to modify characters before echoing, and he's just giving passwords as an example of this. One common use is uppercasing a sign-on or other field to indicate that it's case-insensitive.

    When doing this, remember to unbuffer STDOUT, as in:

    use warnings; use strict; use Term::InKey; use IO::Handle; STDOUT->autoflush(1); my $x=''; print "receiving chars\n"; while ($x ne 'x') { $x = ReadKey(); print uc($x); }
    Hope this helps.
Re^2: Editing STDIN
by Not_a_Number (Prior) on Dec 16, 2006 at 20:52 UTC

    I'm sorry, but I downvoted this node, for two reasons:

    1) It adds nothing to Corion's reply, posted more than four and a half hours earlier.

    2) Like the earlier response, it still doesn't address one of the OP's main problems, namely: 'One of our competition questions requests that we display input using asterisks'...

    Edit: Sincere apologies. Ignore the above! I misread use Term::InKey; as use Term::ReadKey;

    vladdrak+++, Not_a_Number--