I am using the here doc to print usage messages for the user. Is there a way to print 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?
1) You can simply include ANSI codes into heredoc:
print <<EOD;
XXXX\033[1;30;40m YYYY\033[1;33;43m ZZZZ\033[0mRESET
EOD
2) Heredoc interpolates the variables, so if you include ANSI colors into 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) Building on #2, you can generate ANSI codes via Term::ANSIColor's color()
method as a string and use the variable containing that string in the heredoc. Sorry, no working example since I don't have ANSIColor installed but should be obvious.
You may want to store a specific ANSI code in some specific variable and put the actual text in heredoc and sprincle ANSI-code variables there.
"blah"
where you put <<"DOC"
. For example, foo(1, <<"EO_SPECIAL", 2);
. See how the rest of the syntax stays the same around it? It would be just supericky to wait for the , 2);
part until after the line containing only EO_SPECIAL
, you know? So do the same with a semicolon. –
Annamariaannamarie return eval(dequeue("|QQ|", <<"VALIDATE_PROPERTY")) || 0;
. See how that works? –
Annamariaannamarie Term::ANSIColor
, and afterwards you'll actually be able to understand what's going on without either remembering a lot of shit or looking the escapes up every time. –
Farly This is my$__ANSI_BLUE comment
–
Herr ${var}
to access $var
and make the variable references stand out a bit more. It will also help you when you try to write something like ${bold}word${reset}
. –
Tarnopol You can use the @{[expression]}
syntax within a heredoc to evaluate arbitrary code. The output of this little program will look OK if your terminal has a dark background and light foreground 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
© 2022 - 2024 — McMap. All rights reserved.