Pergunta

Is there a way to underline the text is a perl output script? I have read from several sources but the text in the scripts can't be underlined.

An error outputs: Global symbol "$finalAddition" requires explicit package name at C:\Documents and Settings\PCS\Desktop\Perl Scripts\script.pl line 7.

The Script Codes:

#!/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');

Please give some advice on this. Thanks.

Foi útil?

Solução 2

After rounds of testing and almost smashing the screen, the answer was pretty simple actually... [EDIT] New and better codes!

#!/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";

Thanks for the code advices!

Outras dicas

This might be to do with variable scoping and having enabled strict mode, rather than what you are trying to achieve. Does changing adding a "my" to the code change anything?

#!/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');
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top