Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Spinning cursor while waiting for search/copy process to be finished

by johngg (Abbot)
on Mar 11, 2013 at 11:13 UTC ( #1022783=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Spinning cursor while waiting for search/copy process to be finished
in thread Spinning cursor while waiting for search/copy process to be finished

I'm not sure why you are passing an argument to your spin subroutine and then feeding that back around as you do. You are not returning any thing explicitly from the subroutine so the likelihood is that it returns 1 denoting success of the last print statement in the loop.

You could make your subroutine into a closure, i.e. a reference to a subroutine, so that each time it is called it outputs the next symbol. That way, you don't have to worry about the looping logic in your subroutine but just call it whenever you want to show the next symbol. It is also probably a good idea to only show the next symbol once every 50 or 100 times around your logic loop, depending on the speed of that loop, as outputting a symbol every time will slow your program down.

$ perl -MTime::HiRes -MFcntl -Mstrict -Mwarnings -e ' > STDOUT->autoflush( 1 ); > > my $spinner = do { > my $idx = 0; > my @symbols = ( q{-}, q{\\}, q{|}, q{/} ); > sub { > print $symbols[ $idx ++ ], qq{\b}; > $idx = 0 if $idx > $#symbols; > }; > }; > > for my $loop ( 1 .. 10_000 ) > { > $spinner->() unless $loop % 50; > Time::HiRes::sleep( 0.01 ); > } > print qq{\n};' / $

I hope this is helpful.

Cheers,

JohnGG


Comment on Re^3: Spinning cursor while waiting for search/copy process to be finished
Select or Download Code
Re^4: Spinning cursor while waiting for search/copy process to be finished
by Ingvar (Novice) on Mar 11, 2013 at 12:39 UTC

    Aha, it works with the loop! thank you so much! Next I will try to squeeze it somehow into my original code above and then write back...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (18)
As of 2014-07-11 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (235 votes), past polls