How do I print something out in color?

Perl Items

Moderator: daniel

User avatar
Site Admin
Posts: 238
Joined: Tue Jan 09, 2007 9:54 pm

How do I print something out in color?

Postby daniel » Thu Apr 14, 2011 11:31 am

In general, you don't, because you don't know whether the recipient has a color-aware display device. If you know that they have an ANSI terminal that understands color, you can use the Term::ANSIColor module from CPAN:

Code: Select all

use Term::ANSIColor;
print color("red"), "Stop!\n", color("reset");
print color("green"), "Go!\n", color("reset");

Or like this:

Code: Select all

use Term::ANSIColor qw(:constants);
print RED, "Stop!\n", RESET;
print GREEN, "Go!\n", RESET;

Further info Here

Return to “Perl”

Who is online

Users browsing this forum: No registered users and 1 guest