Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to Run a section of code for a particular amount of time ?

by Ratazong (Monsignor)
on Nov 11, 2016 at 09:54 UTC ( #1175730=note: print w/replies, xml ) Need Help??


in reply to How to Run a section of code for a particular amount of time ?

Measure the time spent in the loop and create an additional exit condition. As the main time in your loop is spent sleeping for one second, you may as well count how often the loop has been executed, as shown below

HTH, Rata

my $count = 0; until((@window3=FindWindowLike(undef,"calculator")) || ($count > 29)) { print("\ncan't find window\n"); sleep 1; $count ++; }
  • Comment on Re: How to Run a section of code for a particular amount of time ?
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-06-04 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?