Perl Terminal Colours

This example shows how to print some colours with Perl.

print "e[37m whiten";
print "e[33m yellown";
print "e[36m cyann";
print "e[34m bluen";
print "e[32m greenn";
print "e[35m majentan";
print "e[31m redn";
print "e[30m blackn";
print "e[37m back to whiten";

The result looks like this:


On some Terminal it don’t work, so another solution is to use the Module Term::ANSIColor:

use strict;
use Term::ANSIColor;

my @color = qw(black red green yellow blue magenta cyan white);

for my $col (@color){
	print color($col),$col, color($col),"\n";
print "default\n"

Result is now:


Leave a Reply

Your email address will not be published.

three × four =