in reply to while loop acting up, though I'm not sure how

What's going on, please, and why?

I'll have a crack at answering this. Its easier to understand when you simplify it down to psuedo-code:

while set $time to current time test $time < $expiry fail: break loop test $time - $prevtime >= 10 fail: sleep 10 $prevtime = $time warn $time
So, this is what is happening:
$expiry = 3600 $prevtime = undef $time = undef 1st loop: $time = 123 $time 123 < $expiry 3600 (true) $time 123 - $prevtime undef >= 10 (true) $prevtime = 123 warn $time 123 2nd loop: $time = 123 (first iteration takes less than 1 second) $time 123 < $expiry 3600 (true) $time 123 - $prevtime 123 >= 10 (false) sleep 10 $prevtime = 123 warn $time 123 3rd loop: $time = 133 (slept on last iteration so advance 10s) $time 133 < $expiry 3600 (true) $time 133 - $prevtime 123 >= 10 (true) $prevtime = 133 warn $time 133 4th loop: $time = 133 (last iteration took less than 1s) ...
You can clearly see the pattern of sleep, no sleep, sleep, no sleep. Essentially the even iterations are doing the 2nd iteration and odd iterations are doing the 3rd iteration (just advancing numbers in each case).

That is what is happening. Why it is happening is because you set a fixed point in time and then use current time to compare it, mixing in a bit of sleeping as well. This effectively shifts your processing from working in the now to working in the past (or future, depending on your perspective) and then updating to work on the now again for the next loop (but still comparing your now value to the previous past value).

Replies are listed 'Best First'.
Re^2: while loop acting up, though I'm not sure how
by msh210 (Monk) on Nov 17, 2015 at 16:56 UTC
    Thank you!

      You're welcome

      Its good practice to write up what you want to do in psuedo-code and run a few iterations by hand, to get a feel for the logic you are attempting. Once you've got a bit more experience it'll become second nature and you start being able to do simple ones like this in your head ;-)

      Good luck!