getting closer on the timer

Discussion in 'Perl' started by fnord, Aug 22, 2003.

  1. fnord

    fnord Guest

    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?
    fnord, Aug 22, 2003
    #1
    1. Advertising

  2. fnord

    Eric Frazier Guest

    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?
    Eric Frazier, Sep 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DaKitty
    Replies:
    26
    Views:
    1,239
    Duende
    Nov 24, 2004
  2. tshad
    Replies:
    0
    Views:
    385
    tshad
    Jun 22, 2007
  3. Adrienne Boswell

    Re: Stylesheet to make IE and FF closer?

    Adrienne Boswell, Feb 8, 2009, in forum: HTML
    Replies:
    4
    Views:
    340
    Adrienne Boswell
    Feb 8, 2009
  4. Zed Shaw
    Replies:
    0
    Views:
    101
    Zed Shaw
    Mar 28, 2006
  5. Michael Satterwhite

    Can't install rubygems - but getting closer

    Michael Satterwhite, Aug 7, 2006, in forum: Ruby
    Replies:
    1
    Views:
    90
    Michael Greenly
    Aug 7, 2006
Loading...

Share This Page