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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re^3: Spinning cursor while waiting for search/copy process to be finished by johngg
in thread Spinning cursor while waiting for search/copy process to be finished by Ingvar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found