Dear wise ones,

I have created a utility written in Perl for use by members of my department. If it is invoked with a parameter of "-h" it writes help information to the screen. I have near the top of the script

   use Term::ANSIColor qw (color colored colorstrip :constants);

which allows me to color keywords in the help text that is generated. When I display the help text, if I use the regular print function, strings like

   "The purpose of the " . colored ("ts", "green") . " script is to ..."

work perfectly. However, I just tried using a format and the write instruction to generate the same information with better formatting, and found that the ANSII codes that are properly interpreted and rendered by the print instruction are being displayed by the write function as text, e.g.

The purpose of the [32mts [0m script is to search for a ...

Is there a way to use the write function and a format to display text with embedded ANSII codes being interpreted as control characters rather than as text?

Thank you.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.