in reply to Re: Spining "stick"
in thread Spining "stick"

It is a good use for carriage return and select to get a sub 1 sec sleep. A variation on this is wget style progress bar if that is more approptriate to the task at hand ie you know how far you are through the task.

while( $waiting or 1 ) { spin(); } { my $c=0; # closure to remember spin state sub spin { local $| = 1; print "\r", qw( | / - \ )[$c++%4]; select undef, undef, undef, 0.25; # sleep 250 msec } }

Unbuffered output as per beebles note.

cheers

tachyon

Replies are listed 'Best First'.
Re^3: Spining "stick"
by beable (Friar) on Jul 03, 2004 at 12:28 UTC
    This was producing no output on my system, unless I commented out the select line. Replacing select with a sleep also produced no output. But I worked it out, by adding a line saying local $| = 1; to the start of the program, I got output.