John Serink wrote:
> Hi All:
> 
> Ok, I need to use either Win32::Console or Term::ANSIScreen depending
> whether I'm on a Linux platform or Windoze box, so I do this:
> if($^O eq "MSWin32"){
> # Check which OS
>       print("Looks like its $^O\n");
>       require Win32::Console;
> } else {
>       require Term::ANSIScreen;
> }
> Works fine, however, later on the code I need to create a console object
> like this:
> if($^O eq "MSWin32"){
> # Check which OS
>       $console = Win32::Console->new(STD_OUTPUT_HANDLE);
> } else {
>       $console = Term::ANSIScreen->new();
> }
> 
> And that is the fly in the ointment. I get an error about
> STD_OUTPUT_HANDLE as it's a constant in the Win32::Console module but
> its not loaded yet on Windows and never loads on Linux, so the error
> makes the script abort.
> 
> D:\linux>perl init25g.pl 192.168.1.27 4002 client 10 13
> Bareword "STD_OUTPUT_HANDLE" not allowed while "strict subs" in use at
> init25g.pl line 73.
> 
> Execution of init25g.pl aborted due to compilation errors.
> 
> How do I get around this?

You could do something like:

my $windoze;

BEGIN {
        $windoze = 1 if $^O eq 'MSWin32';
        if ($windoze) {
                print "Looks like its Windoze\n";
                eval "use Win32::Console";
        } else {
                print "Looks like its not Windoze\n";
                eval "use Term::ANSIScreen";
        }
}

# ...

my $console;
if ($windoze) {
        print "Win32::Console \n";
        $console = Win32::Console->new(STD_OUTPUT_HANDLE);
} else {
        print "Term::ANSIScreen  \n";
        $console = Term::ANSIScreen->new();
}


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to