davies has asked for the wisdom of the Perl Monks concerning the following question:
Running this for about a second results in half a million iterations. But I can’t work out how to do the same thing in Perl.count! = 0 DO datain$ = INKEY$ count! = count! + 1 LOOP UNTIL LEN(datain$) > 0 PRINT count!
Another way, based on Perl cookbook recipe 15.6:use strict; use warnings; use diagnostics; my $count = 0; my $char; until (sysread STDIN, $char, 1) { $count++; } print $count;
What happens:use strict; use warnings; use diagnostics; use Term::ReadKey; my $count = 0; my $char; ReadMode('cbreak'); while ($char eq "") { $char = ReadKey(0); $count++; } print $count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem running code until a user hits a key
by jaldhar (Vicar) on Dec 30, 2007 at 15:45 UTC | |
|
Re: Problem running code until a user hits a key
by jasonk (Parson) on Dec 30, 2007 at 15:50 UTC | |
|
Re: Problem running code until a user hits a key
by dsheroh (Monsignor) on Dec 30, 2007 at 16:27 UTC | |
by davies (Monsignor) on Dec 30, 2007 at 17:17 UTC | |
by dsheroh (Monsignor) on Dec 31, 2007 at 03:03 UTC | |
by davies (Monsignor) on Dec 31, 2007 at 12:04 UTC |