Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Color in windows command prompt

by g_speran (Scribe)
on Jan 16, 2018 at 22:50 UTC ( [id://1207377]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207377]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found