Dave Whipp wrote:

You can use "{time - $epoch}" or "{time.as<%d>}" or "{int time}". (That last one is not "{+time}", because that would be a floating-point value, not an integer).

I was thinking: an epoch is just a time, and "int time" is a duration -- the number of seconds since the current epoch. So, the following should work:

for 1 .. 2 -> {
   use epoch time();
   sleep 6;
   say int time;
}

This should print something close to "6", twice.

But something niggled me: does the value of the RHS of a "use" get evaluated at run time, or compile time? In perl5, that could definitely would only execute the C<use> once.

I could see 3 possible behaviors:

1. C<use> sets the epoch for each iteration of the loop, thus calling time() one per iteration

2. C<use> executes just once, at compile time. Thus seconds iteration prints approximately "12"

3. C<use> does a compile-time binding of the epoch to the time() function. So each iteration prints "0".


Which actually happens?

Reply via email to