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! | [reply] [Watch: Dir/Any] [d/l] [select] |
Oops. I Posted the above about the select() function Anonymously. So if it doesn't work, you now know who to flame :)
Joe
| [reply] [Watch: Dir/Any] |
Funny you ask that. My origianl version was something like the following (adjust $delay according to the speed of your system)
use Tie::Cycle;
my $delay=100;
tie my $spinner, 'Tie::Cycle', [map {("\b$_") x $delay} qw(\ | / -)];
which is an approach I prefer to sleeping, as normally you put a spinner in a time sensitive loop so that you know its doing something... Also when ive used this the actual work happening in the loop is complicated (ie slow enough) that the spinner turns at a reasonable speed. In fact from a diagnostic POV its probably better to let it spin freely with no delay at all. That way you can observe the underlying task slow down or speed up (for whatever reason). For example you might use it when reading a file into a hash. When the hash starts having to resize itself you can observe the spinner stop briefly. Or when doing a massive DB update you can see the load on your network and DB server....
Cheers,
--- demerphq
my friends call me, usually because I'm late....
| [reply] [Watch: Dir/Any] [d/l] |