How can I print to a terminal in color?

This will only work if the terminal you're using supports color. And be warned that the user may have changed their background color.


Use a module called Term::ANSIColor. This module makes it very simple to color your terminal output:

    use strict;
    use warnings;
    use Term::ANSIColor;

    print color("red"), "Red!\n", color("reset");
    print color("blue"), "Blue!\n", color("reset");

    exit 0;

See Also

    perldoc -q 'color'
    perldoc Term::ANSIColor
Revision: 1.5 [Top]