f28be357 f28be357 -4 years ago 68
Perl Question

errer in code loading in perl

What is the problem I do not want to Please Wait be repeated



#!/usr/bin/perl
Win32::Console;
use strict;
use warnings;
$|++; # turn off output buffering;

my @chars = qw(| / - \ );

my $i = 0;
my $v = "Please Wait";
print $chars[$i];

while (1) {
sleep 1;
print "$v\b", $chars[++$i % @chars];
}





What is the problem I do not want to Please Wait be repeated

Answer Source

You are putting print "Please wait" inside the while loop, so it will keep printing. Also use \b after the $chars print and not after Please wait

#!/usr/bin/perl
use Win32::Console;
use strict;
use warnings;
$|++; # turn off output buffering;

my @chars = qw(| / - \ | / - \\);

my $i = 0;
my $v = "Please Wait";
print $v;
while (1) {
    sleep 1;
    print $chars[++$i % @chars],"\b";
}

EDIT, as per your comment to request using dots instead. if you want to run Please wait... then get rid of the \b

#!/usr/bin/perl
use Win32::Console;
use strict;
use warnings;
$|++; # turn off output buffering;

my @chars = qw(.);

my $i = 0;
my $v = "Please Wait";
print $v;
while (1) {
    sleep 1;
    print $chars[++$i % @chars];
}

Second Edit.... to have single dot in while.

#!/usr/bin/perl
use Win32::Console;
use strict;
use warnings;
$|++; # turn off output buffering;

my @chars = qw(.);

my $i = 0;
my $v = "Please Wait";
print $v;
while (1) {
    sleep 1;
    print $chars[++$i % @chars],"\b";
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download