Hi Johan,

In a message dated 10/18/2007 11:34:29 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:


> I have a Perl application that should work on both Windows and Linux.
> On Windows I use some of the Windows-specific modules, e.g.
> "Win32API::File". So my code have things like:
> 
> 1) "use Win32API::File qw( :ALL )  "
> 2) use of "constans" like GENERIC_WRITE and FILE_SHARE_DELETE.
> 3) calls to functions like Win32::File::CreateFile
> 
> In all my Perl-files i have "use strict". My problems at first on Linux are:
> 
> - the lines "use XYZ" where XYZ is a Windows module can't be used on
> Linux. Somehow they have to be skipped.
> 

The "standard" solution (published in The Perl Journal in 1999), which I got 
first from Bruce Winter's Misterhouse but have since used in several locations 
and articles. It extends easily to handle several sets of "parallel" modules:

use strict;
use vars qw($OS_win);

BEGIN {
        $OS_win = ($^O eq "MSWin32") ? 1 : 0;

        print "Perl version: $]\n";
        print "OS   version: $^O\n";

            # This must be in a BEGIN in order for the 'use' to be 
conditional
        if ($OS_win) {
            print "Loading Windows module\n";
            eval "use Win32::SerialPort";
        die "[EMAIL PROTECTED]" if ($@);

        }
        else {
            print "Loading Unix module\n";
            eval "use Device::SerialPort";
        die "[EMAIL PROTECTED]" if ($@);
        }
} # End BEGIN

-bill


**************************************
 See what's new at 
http://www.aol.com
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to