Win32::SerialPort (under Windows)
Device::SerialPort (else)
I know it is possible to detect the OS using Config::Config. But it
seems not possible to use different modules depending on this
information like this:
if ( $OS eq 'WINDOWS' ) {
use Win32::SerialPort qw( :PARAM :STAT );
} else {
use Device::SerialPort qw( :PARAM :STAT );
}
What's the right way to write such an OS dependent application?
Steffen
I don't know about "right", but this is one way:
BEGIN {
if ( $^O eq 'MSWin32' ) {
require Win32::SerialPort;
import Win32::SerialPort qw( :PARAM :STAT );
} else {
require Device::SerialPort;
import Device::SerialPort qw( :PARAM :STAT );
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Thanx Gunnar. That was the solution. And sorry for my impatience. ;-)
This is explained about halfway down in the documentation for "use".
The "BEGIN" forces the "require" and "import" to happen at
compile time.
>What's the right way to write such an OS dependent application?
Don't use use() but an explicit require() and import() without the
enclosing BEGIN.
jue
s/without/with/
<snip>
> if ( $^O eq 'MSWin32' ) {
I prefer
if ( $^O =~ /Win32/i ) {
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>