2
我新的Perl和诅咒,但我努力让我的代码来运行一个循环,先从这里是我的代码:Perl的诅咒:: UI - 循环
#!/usr/bin/env perl
use strict;
use Curses::UI;
sub myProg {
my $cui = new Curses::UI(-color_support => 1);
my $win = $cui->add(
"win", "Window",
-border => 1,
);
my $label = $win->add(
'label', 'Label',
-width => -1,
-paddingspaces => 1,
-text => 'Time:',
);
$cui->set_binding(sub { exit(0); } , "\cC");
# I want this to loop every second
$label->text("Random: " . int(rand(10)));
sleep(1);
$cui->mainloop();
}
myProg();
正如你所看到的我想这部分递归运行:
# I want this to loop every second
$label->text("Random: " . int(rand(10)));
sleep(1);
投入标签的随机数的想法是只是为了显示它的工作原理,我将最终有会定期更换相当多的标签,想办其他功能也是如此。
我试着这样做:
while (1) {
...
}
,但如果我这样做,主循环之前();调用窗口永远不会创建,调用之后它什么也不做?
希望这有意义吗?那我该怎么做呢?