Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   getting closer on the timer (http://www.velocityreviews.com/forums/t24306-getting-closer-on-the-timer.html)

fnord 08-22-2003 02:58 PM

getting closer on the timer
 
Here's what I've got for the timer:

#################################
# timer
#################################
sub timer
{
$timeout = 180;
$SIG{ALRM} = sub {die;};
eval
{
alarm($timeout);
$start = time();

print "Welcome to the game, here are your letters:\n";
&reg_roll();
print "\n";

$timeRemaining = $timeout - (time() - $start);
while ($timeRemaining > 0)
{
alarm($timeRemaining);
&input;
}
};
print "\nTime's up!\n";
}


For some reason it's not timing out after 180 seconds, it's running for anywhere from 6 to 9 minutes.

Any ideas as to why?

Eric Frazier 09-12-2003 03:20 AM

Re: getting closer on the timer
 
Hi,

What do time() and &input do/return? I don't see how you ever get to
&input if for some reason $timeremaining never gets to zero. Can't tell
much else withone knowing how the whole thing works though. First thing
I would do is print to a file the loop values, and make sure they are
incing like you expect them to. I also would wonder how alarm deals with
non integer numbers, maybe it just rounds to the int, but make it does
something weird.

Eric

fnord wrote:
>
> Here's what I've got for the timer:
>
> #################################
> # timer
> #################################
> sub timer
> {
> $timeout = 180;
> $SIG{ALRM} = sub {die;};
> eval
> {
> alarm($timeout);
> $start = time();
>
> print "Welcome to the game, here are your letters:\n";
> &reg_roll();
> print "\n";
>
> $timeRemaining = $timeout - (time() - $start);
> while ($timeRemaining > 0)
> {
> alarm($timeRemaining);
> &input;
> }
> };
> print "\nTime's up!\n";
> }
>
> For some reason it's not timing out after 180 seconds, it's running for anywhere from 6 to 9 minutes.
>
> Any ideas as to why?



All times are GMT. The time now is 10:44 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.