Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How to print colored word in text file

by vkp (Novice)
on Jun 21, 2013 at 06:49 UTC ( #1040086=perlquestion: print w/ replies, xml ) Need Help??
vkp has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How i can print a specific word say "ERROR" in red color in a text file. And i need to do this for windows and linux. Regards

Comment on How to print colored word in text file
Re: How to print colored word in text file
by Happy-the-monk (Monsignor) on Jun 21, 2013 at 07:06 UTC

    red color in a text file

    Colour as in coloured text is some kind of formatting.

    Text files are understood as to contain text, but no such formatting.

    So the answer is you don't. In order to colour text, you need an output format that can colour text like some rich text format or html. Do you have something in mind already?

    Cheers, Sören

    (hooked on the Perl Programming language)

Re: How to print colored word in text file
by RichardK (Priest) on Jun 21, 2013 at 11:05 UTC

    Term::ANSIColor will let you write coloured text to the screen. And you can store those ANSI codes in a text file, if that's any use to you?

      Have you been able to use this successfully in Windows cmd.exe? I have tried but it did not work (at least in Windows 7 that I have).

        No, sorry but I don't run windows. I thought it worked to some limited extent on windows, but I guess I'm wrong.
        Same problem as hdb; may be user-error, but I can't recall ever (on M$ osen) making Term::ANSIColor work as advertized.

        If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: How to print colored word in text file
by pvaldes (Chaplain) on Jun 22, 2013 at 09:24 UTC

    I need to do this for windows and linux

    use Term::ANSIColor qw(:constants); print BOLD, RED, "ERROR!! Muahahahaha!!!\n", RESET; print "I'm fine now, thanks\n";

    Note: Term::ANSIColor comes with the perl-modules package in Debian, replacing the old libansicolor-perl package

    in a text file

    See. i.e. Latex \usepackage{color} and use perl to print the latex command to an outfile.tex, then convert outfile.tex to outfile.pdf with pdflatex

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1040086]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-09-18 23:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls