ttlgreen has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm trying to figure out how to test if the Term::ANSIColor module is present, and if so "use" it.
I'm trying to get the equivalant functionality as doing:
use Term::ANSIColor qw(:constants);
The problem is I need to use require instead so the script doesn't exit when it's not found, and I can't seem to get the :constants that way...
The code:
my $can_color = 0; eval { require Term::ANSIColor; }; unless ($@) { ## I tried these next two lines but it does NOT seem to work (compla +ins about the constants not being defined)... Term::ANSIColor->import(); Term::ANSIColor->import(qw(:constants)); $Term::ANSIColor::AUTORESET = 1; $can_color = 1 }
What could I be missing?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can't seem to import properly when using require
by Anonymous Monk on Feb 26, 2012 at 22:29 UTC | |
by ttlgreen (Sexton) on Feb 26, 2012 at 23:35 UTC | |
by tye (Sage) on Feb 27, 2012 at 02:05 UTC |