Main Content
Coloured text in a terminal from Perl Archive - Originally posted on "The Horse's Mouth" - 2006-05-29 14:28:36 - Graham Ellis
If you're looking to do something in Perl and the back of your mind tells you that, surely, someone's done this before then there are two things to note:
• Someone probably HAS and
• It's probably available on the CPAN or as a built in module.
Thus when I was asked the question "How do I get coloured text in a terminal window in Perl" last week, I know there was going to be a module out there - and there is - Term::ANSIColor .
As ever, there's an excellent set of reference notes on th CPAN, but no complete cut-and-paste-this sample for you to try out, so I've written one and it's available here .
Some other articles
P219 - Libraries and Resources What do I mean when I add things in Perl? The week before Christmas Expect in Perl - a short explanation and a practical example Syncronise - software, trains, and buses. Please! Operator overloading - redefining addition and other Perl tricks Loading external code into Perl from a nonstandard directory Do not re-invent the wheel - use a Perl module Debugging and Data::Dumper in Perl About dieing and exiting in Perl Using English can slow you right down! Ordnance Survey Grid Reference to Latitude / Longitude Outputting numbers as words - MySQL with Perl or PHP Judging the quality of contributed Perl code Self help in Perl This article Why reinvent the wheel Use standard Perl modules Where do Perl modules load from Avoid the wheel being re-invented by using Perl modules Talk review - Idiomatic Perl, David Cross P212 - More on Character Strings Binary data handling - Python and Perl First match or all matches? Perl Regular Expressions Converting codons via Amino Acids to Proteins in Perl Possessive Regular Expression Matching - Perl, Objective C and some other languages Serialsing and unserialising data for storage and transfer in Perl The difference between dot (a.k.a. full stop, period) and comma in Perl Single and double quotes strings in Perl - what is the difference? DNA to Amino Acid - a sample Perl script How much has Perl (and other languages) changed? Looking ahead and behind in Regular Expressions - double matching Object Orientation in an hour and other Perl Lectures Arrays v Lists - what is the difference, why use one or the other Further more advanced Perl examples Unpacking a Perl string into a list Teaching examples in Perl - third and final part Binary data handling with unpack in Perl Want to do a big batch edit? Nothing beats Perl! Making variables persistant, pretending a database is a variable and other Perl tricks Running a piece of code is like drinking a pint of beer Perl substitute - the e modifier Finding words and work boundaries (MySQL, Perl, PHP) Equality and looks like tests - Perl Handling Binary data (.gif file example) in Perl Ignore case in Regular Expression Regular expressions made easy - building from components Substitute operator / modifiers in Perl Commenting a Perl Regular Expression Perl, the substitute operator s Matching within multiline strings, and ignoring case in regular expressions C++ and Perl - why did they do it THAT way? This article Don't expose your regular expressions Storing a regular expression in a perl variable Perl Regular Expressions - finding the position and length of the match Remember to process blank lines Commenting Perl regular expressions