Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Way of the Spinner (repost)

by HamNRye (Monk)
on Jan 17, 2003 at 22:07 UTC ( [id://227817]=note: print w/replies, xml ) Need Help??


in reply to Re: Way of the Spinner (repost)
in thread Way of the Spinner (repost)

Any way to keep this from spinning like a top?? Tried it out and on my 2.4GHZ system, it is almost a white circle.

~Hammy

Replies are listed 'Best First'.
Re: Re: Re: Way of the Spinner (repost)
by Anonymous Monk on Jan 18, 2003 at 03:59 UTC
    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!
      Oops. I Posted the above about the select() function Anonymously. So if it doesn't work, you now know who to flame :) Joe
Re: Re: Re: Way of the Spinner (repost)
by demerphq (Chancellor) on Jan 20, 2003 at 15:55 UTC
    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....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://227817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found