How to print BOLD text here doc in Perl?

I am using a document here to print usage messages for the user. Is there a way to print specific BOLD words, similar to man pages on unix. I use this on Unix. Is there a way to use Term :: ANSIColor (or some other way?) With this document?

+4
source share
2 answers

1) You can simply include ANSI codes in the heredoc:

print <<EOD; XXXX\033[1;30;40m YYYY\033[1;33;43m ZZZZ\033[0mRESET EOD 

2) Heredoc interpolates variables, so if you include ANSI colors in a variable, it works.

 my $v="xxxxx"; $var = "\nXXXX\033[1;30;40m YYYY\033[1;33;43mZZZZ\033[0mRESET\n"; print <<EOD; $var EOD 

3) Based on # 2, you can generate ANSI codes using the Term :: ANSIColor color() method as a string and use the variable containing this string in the heredoc . Sorry, there is no working example, since I do not have ANSIColor installed, but it should be obvious.

You may want to store the specific ANSI code in some specific variable and put the actual text in the heredoc and sprincle ANSI code variables there.

+9
source

You can use the syntax @{[expression]} in heredoc to evaluate arbitrary code. The result of this small program will look fine if your terminal has a dark background and foreground background color:

 use Term::ANSIColor; print <<EOF; I am using the here doc to print usage messages for the user. Is there a way to print @{[colored['bright_white'],'specific words']} BOLD similar to the man pages on unix. I am using this on Unix. Is there a way to use Term::ANSIColor (or some other way?) with the here doc? EOF 
+4
source

All Articles