Thanks for your help. I have defined $console  as a global hash reference
and then I call $console = Win32::Console->new(STD_OUTPUT_HANDLE); in my
module.

It works fine for me now.

Thanks,
Jai!





On Tue, Mar 31, 2009 at 11:12 PM, Sisyphus <sisyph...@optusnet.com.au>wrote:

>
> ----- Original Message ----- From: "Perl Help" <perlhel...@gmail.com>
> To: "Sisyphus" <sisyph...@optusnet.com.au>
> Cc: <perl-win32-users@listserv.activestate.com>
> Sent: Wednesday, April 01, 2009 9:32 AM
> Subject: Re: Reset in ANSIColor sets the background to black
>
>
>  Hi Rob,
>>
>> I am facing another problem with this code. When I call the function twice
>> in the same script, it throws me the following error:
>>
>> Error Msg: Test[This is in Red color as expected for the first function
>> call]
>> Use of uninitialized value in bitwise and (&) at test.pl line 12.
>>
>> My Script is :
>>
>> #########33 START #########3
>> use strict;
>> use warnings;
>> use Win32::Console;
>>
>> ErrorMsg('Test');
>> ErrorMsg('Test');
>>
>> sub ErrorMsg {
>>  my $error = shift;
>>  my $console = Win32::Console->new(STD_OUTPUT_HANDLE);
>>  my $CurrentConsoleColor = $console->Attr;
>>  my $BackgroundColor = $CurrentConsoleColor &
>> (BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
>>  # This sets the text color on DOS in red with intensity
>>  $console->Attr(FOREGROUND_RED|FOREGROUND_INTENSITY|$BackgroundColor);
>>  print "\nError Msg: $error \n";
>>  $console->Attr($CurrentConsoleColor);
>> }
>>
>
> Hi Jai,
> One solution is to create and assign to $console outside of the subroutine
> (and before the subroutine is called). This works fine for me:
>
> #################################
> use strict;
> use warnings;
> use Win32::Console;
>
> my $console = Win32::Console->new(STD_OUTPUT_HANDLE);
>
> ErrorMsg('Test');
> ErrorMsg('Test again');
> ErrorMsg(' ... and again');
>
> sub ErrorMsg {
>  my $error = shift;
>  my $CurrentConsoleColor = $console->Attr;
>  my $BackgroundColor = $CurrentConsoleColor &
> (BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
>  # This sets the text color on DOS in red with intensity
>  $console->Attr(FOREGROUND_RED|FOREGROUND_INTENSITY|$BackgroundColor);
>  print "\nError Msg: $error \n";
>  $console->Attr($CurrentConsoleColor);
> }
> #################################
>
> Cheers,
> Rob
>
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to