perl中的代码加载错误
有什么问题我不想再重复了,请等待perl中的代码加载错误,perl,progress-bar,Perl,Progress Bar,有什么问题我不想再重复了,请等待 #/usr/bin/perl Win32::控制台; 严格使用; 使用警告; $|++; # 关闭输出缓冲; 我的@chars=qw(|/-\); 我的$i=0; 我的$v=“请稍候”; 打印$chars[$i]; 而(1){ 睡眠1; 打印“$v\b”,$chars[+$i%@chars]; }您将打印“请稍候”放入while循环中,因此它将继续打印。在打印$chars后使用\b,不要在后使用,请稍候 #!/usr/bin/perl use Win32::C
#/usr/bin/perl
Win32::控制台;
严格使用;
使用警告;
$|++; # 关闭输出缓冲;
我的@chars=qw(|/-\);
我的$i=0;
我的$v=“请稍候”;
打印$chars[$i];
而(1){
睡眠1;
打印“$v\b”,$chars[+$i%@chars];
}
您将打印“请稍候”
放入while循环中,因此它将继续打印。在打印$chars
后使用\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],"\b";
}
如果您计划使用微调器,另一个选择是您可以摆脱sleep 1代码>ad将其替换为选择未定义、未定义、未定义、毫秒
。如果像下面这样使用,旋转器将是又好又快的
#!/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) {
select undef, undef, undef, 0.05;
print $chars[++$i % @chars],"\b";
}
编辑,根据您的评论要求使用点代替。
如果要运行,请稍候…
,然后清除\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];
}
最后,这根本不是一个好方法,但是对于与您在评论中提到的非常相似的等待,这也会起作用
use strict;
use warnings;
$|++;
my @chars = qw( . | | | . .);
print "Please Wait ";
my $i = 0;
while (1) {
select undef, undef, undef, .15;
printf $chars[++$i % @chars];
select undef, undef, undef, .15;
printf $chars[++$i % @chars];
select undef, undef, undef, .15;
printf $chars[++$i % @chars];
printf "\b\b\b";
}
运行时看起来很整洁:)请您将|/-\to替换为。这正是我们正在做的。复制准确的代码并运行它,您将看到。最后的,“\b”
将删除以前的字符,并在每次循环运行时替换为新字符。请将|/-\to替换为。我不知道你在问什么。你想从-
开始吗?我做了一个小编辑。请复制准确的代码并进行测试。