silent Input in PERL

Hello Experts,

I am learning perl. I know ksh/bash/csh...

In ksh I use to do this way... to read user input in silent mode so that nothing returns on the screen.

stty -echo 
read -r pswd
stty echo

Please let me know the way in perl how to do it.
Here are my OS and Perl Details...

$uname -a
Linux sol1 2.6.9-78.0.13.ELsmp #1 SMP Wed Jan 14 16:12:46 EST 2009 i686 athlon i386 GNU/Linux
$ perl -version

This is perl, v5.8.5 built for i386-linux-thread-multi

Please help me....

---------- Post updated at 10:06 AM ---------- Previous update was at 09:00 AM ----------

Experts... no reply....??

See Term::ReadPassword or Term::ReadLine::Gnu

Hi, explorer007.

Also:

       ReadMode MODE [, Filehandle]
               Takes an integer argument, which can currently be one of the
               following values:

                   0    Restore original settings.
                   1    Change to cooked mode.
                   2    Change to cooked mode with echo off.
                         (Good for passwords)
                   3    Change to cbreak mode.
                   4    Change to raw mode.
                   5    Change to ultra-raw mode.
                         (LF to CR/LF translation turned off)

-- excerpt from perldoc Term::ReadKey, q.v.

Using perldoc is a way of solving problems for yourself.

Best wishes ... cheers, drl

-- PS meta-advice -- expecting answers in a specific (and short) amount of time, and bumping posts are behaviours unlikely to win friends and influence people in a positive manner.

1 Like

Also Term::ReadKey:

#!/usr/bin/perl

use Term::ReadKey;

my $key = 0;
my $password = "";

print "\nEnter password: ";

# Loop until enter key is pressed 
ReadMode(4);
while(ord($key = ReadKey(0)) != 10)
{
    if(ord($key) == 127 || ord($key) == 8) {
        chop($password);
        print "\b \b";
    } elsif(ord($key) < 32) {
        # control characters
    } else {
        $password = $password.$key;
        print "*";
    }
}                                                                                                        
ReadMode(0);

print "\n\nYou entered: $password\n";