#!/usr/local/bin/perl -w use strict; use Fcntl; print "Enter some text to lose...\n"; sleep 4; print "Losing...\n"; fcntl(STDIN, F_SETFL, O_NONBLOCK) or die "Couldn't set STDIN to non-blocking I/O: $!\n"; my $buf; 1 while (sysread(STDIN, $buf, 4096)); print "Reading...\n"; fcntl(STDIN, F_SETFL, 0) or die "Couldn't set STDIN to blocking I/O: $!\n"; print scalar ; #### #!/usr/local/bin/perl -w use strict; use Fcntl; print "Enter some text to lose...\n"; sleep 4; print "Losing...\n"; system("/bin/stty raw"); die "stty failed\n" if $?; fcntl(STDIN, F_SETFL, O_NONBLOCK) or die "Couldn't set STDIN to non-blocking I/O: $!\n"; my $buf; print $buf while (sysread(STDIN, $buf, 4096)); print "Reading...\n"; system("/bin/stty cooked"); die "stty failed\n" if $?; fcntl(STDIN, F_SETFL, 0) or die "Couldn't set STDIN to blocking I/O: $!\n"; print scalar ;