ultranerds has asked for the wisdom of the Perl Monks concerning the following question:
..which is called with:sub print_debug { # black red green yellow blue magenta cyan white my ($text, $color) = @_; unless ($color) { print STDERR "$text \n"; } else { use Term::ANSIColor qw(:constants); if ($color =~ /blue/i) { print STDERR BLUE, "$text \n", RESET; } elsif ($color =~ /yellow/i) { print STDERR YELLOW, "$text \n", RESET; } elsif ($color =~ /red/i) { print STDERR RED, "$text \n", RESET; } elsif ($color =~ /blue/i) { print STDERR BLUE, "$text \n", RESET; } elsif ($color =~ /magenta/i) { print STDERR MAGENTA, "$text \n", RESET; } elsif ($color =~ /cyan/i) { print STDERR CYAN ON_GREEN, "$text \n", RESET; } } }
I'm guessing its cos the $color is actually a variable. Is there a way I can do this, or should I just stick with my other solution?sub print_debug { # black red green yellow blue magenta cyan white my ($text, $color) = @_; unless ($color) { print STDERR "$text \n"; } else { use Term::ANSIColor qw(:constants); print STDERR $color, "$text \n", RESET; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Term::ANSIColor - possible to pass color as variable?
by eff_i_g (Curate) on Apr 13, 2011 at 13:18 UTC | |
by ultranerds (Hermit) on Apr 13, 2011 at 13:31 UTC | |
|
Re: Term::ANSIColor - possible to pass color as variable?
by JavaFan (Canon) on Apr 13, 2011 at 13:28 UTC | |
by ultranerds (Hermit) on Apr 13, 2011 at 13:34 UTC | |
|
Re: Term::ANSIColor - possible to pass color as variable?
by thargas (Deacon) on Apr 14, 2011 at 14:11 UTC |