4 ms·
A nicer way to do it that's not as obtuse, since 5.6 is to do use IO::Handle; *STDOUT->autoflush(1); This ends up far clearer than either example, and the
by simcop2387 15y ago
A nicer way to do it that's not as obtuse, since 5.6 is to do
use IO::Handle;
*STDOUT->autoflush(1);
This ends up far clearer than either example, and the idiom even extends easily to all file handles, lexical or otherwise.
EDIT: That being said,
system("sleep 0.02") == 0 or last
is even worse. There is no need to go out to a shell or even an external program for that.
use Time::HiRes;
...
sleep(0.02);
...
Not only will that work on far more systems, it will use less resources and is available to all perl's since 5.7.3 (development release from March 2002, first in stable release from July 2002).
- ttsiodras 15y agoThanks for this. Note that the "sleep" is not part of the plotting script - it's just an example that generates data for plotting. I updated the page with your suggestion.
- chaosfox 15y agojust a correction, you need to import the sleep function from Time::HiRes, otherwise it will use the default sleep function and sleep 0 seconds instead. use Time::HiRes qw/sleep/;