Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > getting closer on the timer

Reply
Thread Tools

getting closer on the timer

 
 
fnord
Guest
Posts: n/a
 
      08-22-2003
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?
 
Reply With Quote
 
 
 
 
Eric Frazier
Guest
Posts: n/a
 
      09-12-2003
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SHA-3 Getting Closer Lawrence D'Oliveiro NZ Computing 0 12-14-2010 08:04 AM
closer...closer....RAM-based system steve NZ Computing 7 09-15-2006 05:10 AM
Mongrel Web Server 0.3.12 -- Updated, Getting Closer Zed Shaw Ruby 0 03-28-2006 03:47 AM
Getting closer to to rip/burn decisions lmnop Computer Support 15 11-27-2004 07:38 PM
getting alot closer. cowboyz NZ Computing 6 11-21-2003 09:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57