2

有没有办法在文本下划线是 perl 输出脚本?我已经阅读了多个来源,但脚本中的文本不能加下划线。

错误输出:全局符号“$finalAddition”需要在 C:\Documents and Settings\PCS\Desktop\Perl Scripts\script.pl 第 7 行显式的包名称。

脚本代码:

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor;

$finalAddition = 8;

print "\n\nThe Final Number after addtion would be ".coloured($finalAddition, 'bold 
underline');

请对此提出一些建议。谢谢。

4

2 回答 2

5

这可能与变量作用域和启用严格模式有关,而不是您想要实现的目标。更改在代码中添加“我的”会改变什么吗?

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor;

my $finalAddition = 8;

print "\n\nThe Final Number after addition would be " .
      colored($finalAddition, 'bold underline');
于 2010-09-17T06:23:01.033 回答
1

经过几轮测试并几乎砸碎屏幕,答案实际上很简单...... [编辑] 新的更好的代码!

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor;

my $totalinput = $userinput * $userinput2;

my $coloredText = colored($totalinput, 'bold underline blue');

print "\n\nThe final answer to the question is: $coloredText\n\n";

感谢您的代码建议!

于 2010-09-17T06:35:34.780 回答