in reply to How to code Pascal's keypressed function in Perl
YuckFoo
#!/usr/bin/perl use strict; my $timeout = 5; while (1) { my $str = getstr($timeout); if ($str ne '') { print "Got it! $str"; } else { print "I got nothing.\n"; } } #----------------------------------------------------------- sub getstr { my ($timeout) = @_; my ($rin, $rout); vec($rin,fileno(STDIN),1) = 1; print "You have $timeout seconds to enter a string:\n"; my $input = select($rout=$rin, undef, undef, $timeout); if ($input) { return <STDIN>; } else { return ''; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to code Pascal's keypressed function in Perl
by Jenda (Abbot) on Aug 04, 2002 at 23:08 UTC |