I don't fully understand why yet; that select(undef....PAUSE) thing eludes
me, but I'll hit the books tonight.
-John


                                                                                       
                            
                    Jeff 'japhy'                                                       
                            
                    Pinyan               To:     [EMAIL PROTECTED]                 
                            
                    <jeffp@crusoe        cc:     [EMAIL PROTECTED]                    
                            
                    .net>                Subject:     Re: timer/display                
                            
                                                                                       
                            
                    07/09/01                                                           
                            
                    02:37 PM                                                           
                            
                    Please                                                             
                            
                    respond to                                                         
                            
                    japhy                                                              
                            
                                                                                       
                            
                                                                                       
                            



On Jul 9, [EMAIL PROTECTED] said:

>I need to come up with a simple status indicator of some sort. I have in
>mind a "spinner." You've seen them before I'm sure, where there's a '-'
>then it changes to '\' then '|' then '/' then '-' and so forth, so that it
>appears to be spinning. Actually, I really don't care what the status
>indicator looks like, I just want it to be easy to code and move in such a
>way that long-time Windows users will understand that the computer is
>working and has not hung. My solution so far is just to tuck a print "*"
>thing in a while loop that's already present doing other work. This is
>inelegant though, as it prints just thousands of asterisks. I was hoping
>someone knew of a better way. Is there a module?

All you need to do is:

  1. fork a process to do the spinning
  2. have it spin
  3. have the main process kill it when the time-consuming part is done

Here's the bare code needed:

  use constant PAUSE => .5;  # time to pause in seconds

  # part 1
  if (my $pid = fork) {
    # DO LONG DBI STUFF

    # part 3
    kill TERM => $pid;  # kill the spinning part
  }
  elsif (defined $pid) {
    # part 2
    my @chars = qw( / - \ | );
    my $i = 0;
    $| = 1;  # turn off output buffering

    while (1) {
      print $chars[$i++], "\r";
      select(undef, undef, undef, PAUSE);
    }
  }

--
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **





Reply via email to