Perl 是否可以使用Term::ReadKey清除终端?
有没有办法用Term::ReadKey模块实现这一点Perl 是否可以使用Term::ReadKey清除终端?,perl,module,console,screen,Perl,Module,Console,Screen,有没有办法用Term::ReadKey模块实现这一点 #!/usr/bin/env perl use warnings; use 5.012; use Term::Screen; say( "Hello!\n" x 5 ); sleep 2; my $scr = Term::Screen->new(); $scr->clrscr(); 我不知道为什么会提供这样的功能,或者它是否提供。但是,如何: #!/usr/bin/env perl use strict; use warni
#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::Screen;
say( "Hello!\n" x 5 );
sleep 2;
my $scr = Term::Screen->new();
$scr->clrscr();
我不知道为什么会提供这样的功能,或者它是否提供。但是,如何:
#!/usr/bin/env perl
use strict; use warnings;
*clrscr = $^O eq 'MSWin32'
? sub { system('cls') }
: sub { system('clear') };
print "Hello\n" for 1 .. 5;
sleep 2;
clrscr();
不确定为什么要使用
Term::Readkey
清除屏幕。它肯定没有这种能力。您是否正在尝试使用标准Perl安装的一部分?您可以使用Term::Caps,这是标准Perl安装的一部分。不幸的是,它要求Termcaps文件在系统上,而Windows没有
use Term::Cap;
#
# Use eval to catch the error when TERM isn't defined or their is no
# Termcap file on the system.
#
my $terminal;
eval {$terminal = Term::Cap->Tgetent();};
#
# Use 'cl' to get the Screen Clearing sequence
#
if ($@) { #Most likely a Windows Terminal
system('cls'); #We really should be doing the 2 line below
# my $clear = "\e[2J"; #But, it doesn't seem to work.
# print "$clear"; #Curse You! I'll get you yet Bill Gates!
} else { #A Real Computer
my $clear = $terminal->Tputs('cl');
print "$clear";
}
print "All nice and squeeky clean!\n";
如果是Windows终端,我试着打印ANSI转义序列,但似乎不起作用
我讨厌做系统调用,因为存在安全风险。如果有人更改了你的
cls
命令怎么办?我想我读错了什么。不记得在哪里了。所以我将坚持使用术语::Screen并使用系统('clear')作为备份。