in reply to Is it possible to include colored text in formatted output using write

Hi, from the doc for Term::ANSIColor:

It's not possible to use this module to embed formatting and color attributes using Perl formats. They replace the escape character with a space (as documented in perlform(1)), resulting in garbled output from the unrecognized attribute. Even if there were a way around that problem, the format doesn't know that the non-printing escape sequence is zero-length and would incorrectly format the output. For formatted output using color or other attributes, either use sprintf() instead or use formline() and then add the color or other attributes after formatting and before output.

Hope this helps!


The way forward always starts with a minimal test.
  • Comment on Re: Is it possible to include colored text in formatted output using write

Replies are listed 'Best First'.
Re^2: Is it possible to include colored text in formatted output using write
by fireblood (Scribe) on May 12, 2023 at 16:21 UTC

    Hi, thank you, this is what I needed to know. I'll now be able to stop needlessly chasing down this path.

    Thanks much and have a great day!