尝试在perl中插入彩色打印时出错

时间:2017-10-28 10:01:49

标签: perl

这就是代码:

print color("red"), "INPUT>"; color("reset"); chomp($ip = <STDIN>);

在cmd中,一切都很好,直到这一行。错误是:在script2.pl第7行调用未定义的子例程&amp; main :: color。

1 个答案:

答案 0 :(得分:6)

使用Term::ANSIColor模块。

来自documentation

use Term::ANSIColor;
print color('bold blue');
print "This text is bold blue.\n";
print color('reset');
print "This text is normal.\n";
print colored("Yellow on magenta.", 'yellow on_magenta'), "\n";
print "This text is normal.\n";
print colored(['yellow on_magenta'], 'Yellow on magenta.', "\n");
print colored(['red on_bright_yellow'], 'Red on bright yellow.', "\n");
print colored(['bright_red on_black'], 'Bright red on black.', "\n");
print "\n";