Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 04 Aug 2005 04:11:25 +0200
From:      Benjamin Lutz <benlutz@datacomm.ch>
To:        Wouter van Rooij <aentgood@gmail.com>
Cc:        questions@freebsd.org
Subject:   Re: perl <stdin>
Message-ID:  <42F1794D.4010602@datacomm.ch>
In-Reply-To: <7603e5d8050803181766be524b@mail.gmail.com>
References:  <7603e5d805080317593a046eec@mail.gmail.com> <7603e5d8050803181766be524b@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigA54FDAC8B111EF2D75C37BE4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Wouter van Rooij wrote:
> \
>
> Hello,
>
> At the first place, sorry for my bad English.
> My question is:
> How can you, when you're writing a perl program, make a input
> (<stdin>) hidden, so that when someone is typing an input in the
> following program is hidden:
> #!/usr/bin/perl
> print "Your name:";
> $name = <STDIN>
> I would like to get the input like this: ********

# stty plays with the terminal characteristics.
# After disabling echo, anything the user types will no
# longer show up on screen.
# Disabling icanon disables buffering. If buffering is
# enabled, you'll get stdin strings only after the user
# presses enter.

system "stty -echo -icanon";

# use sysread() and syswrite() for unbuffered read/write

while (sysread STDIN, $a, 1) {
	if (ord($a) < 32) { last; }
	$b .= $a;
	syswrite STDOUT, "*", 1; # print asterisk
}
print "\nyou said: $b\n";

# Return terminal back to standard mode

system "stty echo icanon";

--------------enigA54FDAC8B111EF2D75C37BE4
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Darwin)

iD8DBQFC8XlRgShs4qbRdeQRAqgKAJ9YERXWXGmQM/axWikDVsgUERvGYACfYCDJ
4sGryozx3tcqOzvaunVAuNQ=
=Qlxy
-----END PGP SIGNATURE-----

--------------enigA54FDAC8B111EF2D75C37BE4--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42F1794D.4010602>