Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Okay, I'm sure that title is worded incorrectly. Anyways, I need to fork (I assume) and sleep for x seconds, then run some code. (The idea is to, in the program, call a line like "sleeprun(60,\&code_to_run);" which will have the code_to_run executed in 60 seconds. I do not want to stop the rest of the program.) Also, this is on Win32. Thanks.

Replies are listed 'Best First'.
Re: Sleep w/o Stopping Program
by the_slycer (Chaplain) on Mar 24, 2001 at 08:58 UTC
    Win32 does support some limited fork()ing (I've used it in 2k without issues - 98 normally crashes though). What you will want to do is something like this:
    my $child; if ($child =fork()){ #continue with prog } elsif ($child == 0){ sleep 60; &code_to_exec; } else { die "Couldn't fork!" }
    See fork for more info
Re: Sleep w/o Stopping Program
by strredwolf (Chaplain) on Mar 25, 2001 at 04:26 UTC
    You need to use the TK module. It has the after command. I use it in my Chatterbox Client.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";