Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I tried this word color output but it gives me:
.[31mword colors .[0m.[31mword colors .[0m.[31mword colors .[0m.[31mword colors .[0m.[31mword colors .[0m.[31mword colors .[0m.[31mword colors
It doesnt want to print the word in red coloring. Do i need to check if I have color-xterm or if I have vt100 on my Windows NT local workstation where I am trying to run this? Here is the script:
use Term::ANSIColor; use strict; my $db = 'bas.txt'; open(DATA, "$db") or die "Can not open: $!\n"; our @dat = (<DATA>); close(DATA); open(DATA, ">$db") or die "NO GO: $!\n"; foreach (@dat) { print DATA color("red"), "word colors\n", color("reset"); } close(DATA);

Replies are listed 'Best First'.
Re: Word Colors
by crenz (Priest) on Aug 28, 2002 at 12:43 UTC

    For the standard windows shell, you need an ANSI interpreter running or else ANSI sequences won't be interpreted. Get ANSI.COM e.g. from http://www.salokin.demon.co.uk/dos_tips.htm. After running it, type bas.txt will show that Term::ANSIColor performs correctly. (Caveat: I don't know whether NT will allow this).

    Which means that you probably have to go a different route to not be dependant on an ANSI interpreter...

    By the way, rxvt (shipped e.g. with msys/mingw) displays the file just fine -- it interpretes ANSI color sequences by itself.

      Windows NT, 2000 and possibly XP do *not* do ANSI color even if you load ansi.sys. If you really need colored text in a "command" window then you have several choices... cygwin or find a way to make BIOS calls from within Perl. I haven't tried the second one but it sure sounds like fun! :) Uh, oh... now I'm gonna have to try.
        You CAN use colors in a DOS box under NT4 or Windows 2000. You have to load system32/ansi.sys in config.nt and use command.com instead of cmd.exe as shell. Unfortunately running perl in such a color DOS box still won't color its output - i think perl uses cmd.exe. How can perl be persuaded to use command.com instead ?
Re: Word Colors
by RMGir (Prior) on Aug 28, 2002 at 12:42 UTC
    It looks like the NT command shell isn't an ANSI terminal.

    Back in the DOS days, I'd have said "put DEVICE=ANSI.SYS into your config.sys", but to tell you the truth I have zero clue how you can make cmd speak ansi...

    If you tried it with a colour xterm to a unix box, I'll bet it'll work...

    Hmm, in fact, it works with Cygwin bash shells; they speak ansi colour codes, it looks like.
    --
    Mike