in reply to Re: Color in windows command prompt
in thread Color in windows command prompt

Figured it out
use if $^O == "WINMS32", Term::ANSIColor => qw(:constants);

Replies are listed 'Best First'.
Re^3: Color in windows command prompt
by syphilis (Archbishop) on Jan 16, 2018 at 23:36 UTC
    use if $^O == "WINMS32", Term::ANSIColor => qw(:constants);

    That's not quite right.
    The condition you want is  $^O eq 'MSWin32'
    The condition you've used will generally evaluate as true on all systems because, in numeric context, both $^O and "WINMS32" are generally 0.
    If you use warnings you should receive 2 warnings - one about the non-numeric nature of "WINMS32" and one about the non-numeric nature of $^O ("MSWin32").

    Also, on perl-5.26.0 at least, I find that if I use strict then I also need to place quotes around Term::ANSIColor.
    This is contrary to the if documentation which states:

    <quote>
    The use of => above provides necessary quoting of MODULE . If you don't use the fat comma (eg you don't have any ARGUMENTS), then you'll need to quote the MODULE.
    </quote>

    I'll submit a bug report about this oversight in the "if" documentation.

    UPDATE: Bug report submitted.

    I personally prefer to use "require" to load modules in this type of situation:
    if($^O eq 'MSWin32') { require Term::ANSIColor; Term::ANSIColor->import(":constants"); }
    Cheers,
    Rob