Hi Bill:
Ok, tried your example, here it is on windows:
use strict;
use warnings;
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();
}
Here is the output:
D:\linux>perl eval1.pl
Looks like its Windoze
Win32::Console
Now, I'm a lazy person and don't want to reboot and go into Linux so I
change the MSWin32 to MWin32 so that the test fails like this:
use strict;
use warnings;
my $windoze;
BEGIN {
$windoze = 1 if $^O eq 'MWin32';
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();
}
Now when I run it:
D:\linux>perl eval1.pl
Looks like its not Windoze
Bareword "STD_OUTPUT_HANDLE" not allowed while "strict subs" in use at
eval1.pl line 22.
Execution of eval1.pl aborted due to compilation errors.
Same problem. See what I mean?
Any thoughts?
> -----Original Message-----
> From: $Bill Luebkert [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 06, 2005 6:42 PM
> To: John Serink
> Cc: [email protected]
> Subject: Re: Cross platform issues
>
>
> 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