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

Hi Monks, I was experimenting with this and I can't get this to work.
#!/tools/gnu/bin/perl-5.6.0-32bit use Term::ANSIColor qw(:constants); # BLACK RED GREEN YELLOW BLUE MAGENTA foreach $num (0 .. 9) { foreach $colour (BLACK, RED, GREEN, YELLOW, BLUE , MAGENTA) { print $colour "$num "; print RESET; } } print "\n";
I don't know much about file handers.

Replies are listed 'Best First'.
Re: Outputing Colour to Screen
by borisz (Canon) on Oct 22, 2004 at 15:31 UTC
    There is nothing to know about filehandles, just put a, after $colour in your code. Since $colour is a string and not a filehandle.
    foreach $num (0 .. 9) { foreach $colour (BLACK, RED, GREEN, YELLOW, BLUE , MAGENTA) { print $colour, "$num ", RESET; } } print "\n";
    Boris
      thanks! it works
Re: Outputing Colour to Screen
by Anonymous Monk on Oct 22, 2004 at 15:34 UTC
    You can use: print $colour, "$num ";
Re: Outputing Colour to Screen
by gothic_mallard (Pilgrim) on Oct 22, 2004 at 15:35 UTC

    Can you tell us more about the problem?

    When you say it isn't working - in exactly what way? Is it doing nothing? Is it producing the wrong results? Does it give an error? etc

    Not sure what you mean about file handlers as you're not doing anything with files in that code.

    Telling us the perl version and OS you're on would be a great help too - especially with any DOS/Terminal et al based scripts.

    --- Jay

    All code is untested unless otherwise stated.

      In his code he has no comma (or dot) between $colour and "$num", this makes Perl assume that $colour is a filehandle. which is why he probably gets the error print() on unopened filehandle