perl <stdin>

Benjamin Lutz benlutz at datacomm.ch
Thu Aug 4 02:11:34 GMT 2005


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";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 186 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20050804/a5f72e70/signature.bin


More information about the freebsd-questions mailing list