Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: enforce timeout in loop

by perlmonkey (Hermit)
on Sep 22, 2003 at 05:28 UTC ( #293088=note: print w/ replies, xml ) Need Help??


in reply to enforce timeout in loop

Follow the example in the perldoc page for alarm. Change your for loop to look like:

foreach my $sleepval (@sleepvals) { eval { local $SIG{ALRM} = sub { die }; alarm 3; sleep($sleepval); }; print strftime "%H:%M:%S", localtime; print "\n"; }


Comment on Re: enforce timeout in loop
Download Code
Replies are listed 'Best First'.
Re: Re: enforce timeout in loop
by semio (Friar) on Sep 22, 2003 at 15:48 UTC
    ++perlmonkey. beautiful. This is exactly what I was looking for.

    cheers, -dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://293088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2015-07-31 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (277 votes), past polls