有沒有辦法用Term :: ReadKey-module來做到這一點?是否可以使用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();
有沒有辦法用Term :: ReadKey-module來做到這一點?是否可以使用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();
我不知道爲什麼會Term::ReadKey提供這樣的功能,或者如果它。但是,如何:
#!/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 ([email protected]) { #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";
我試着打印ANSI Escape序列,如果它是Windows終端,但似乎不起作用。
我討厭做系統調用,因爲存在安全風險。如果某人更改了cls
指令,該怎麼辦?
由於Term :: ReadKey已經在腳本中。 – 2010-11-18 06:23:16
我想我讀了一些錯誤的東西。不記得在哪裏。所以我會堅持使用Term :: Screen並使用system('clear')作爲備份。 – 2010-11-17 19:24:16