You can use the select() function to do short sleeps. If your system doesn't support a four-argument select(), you can use the Time::HiRes module. For the select function, the last argument reflects the time to sleep. This comes right out of O'Reilly's Perl Cookbook:
while (<>) {
select(undef, undef, undef, 0.25);
print;
}
Using Time::HiRes, we'd write it as:
use Time::HiRes qw(sleep);
while (<>) {
sleep(0.25);
print;
}
Funny thing is that I used nearly the same method of making a spinner a while back...and I had the exact same question about slowing it down.
Hope this helps! |