On Mon, 9 Feb 2004, Ricardo Pichler wrote:
> Hi all,
> in some aplicantions, we can see the cursor moving in
> one position, like an "indicator of application is running".
> In the examples that I see, they have made in C/C++.
> It is possible in perl?
>
> Sorry my bad english.
> Thanks in advance!
> Ricardo Pichler
First, your English is fine. Much better than my Portuguese would be!
I tested the following on RedHat Linux 9.0 using Perl 5.8.0. It makes a
rather slow spinner. The alarm() function only has resolution to about 1
second. Spinning faster than once a second or so would require using one
of the other methods mentioned if you do a "perldoc -f alarm", such as
Time::HiRes from CPAN. I don't know if this works the same in Windows or
not. I don't have Perl on my Windows box.
#!/usr/bin/perl
use strict;
use warnings;
our $click=0;
$|=1;
$SIG{ALRM}=sub {
if ($click==0) { print "|\b";$click=1}
elsif ($click==1) {print "/\b";$click=2}
elsif ($click==2) {print "-\b";$click=3}
else {print "\\\b";$click=0}
alarm(10);
};
print "setting alarm\n";
alarm(10);
print "entering for loop\n";
for (;;) { 1}
Replace this for() loop with your code. Note that the $SIG{ALRM}
subroutine must set the alarm again. Also note that only one alarm can be
set at a time. If you set another alarm, the previous alarm is canceled.
This means you can cancel your "spinner" using
alarm(0);
Hope this of use to you.
--
Maranatha!
John McKown
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>