Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon, which comes first ob_start or session, wwwxxx/58/2010, xxxxdup, xxxxdup, mailx informatii, should producers of software-based services, such as atms, be held liable for economic injuries suffered when their systems fail?

Links

XODOX
Impressum

#1: use modules OS dependent

Posted on 2008-04-14 14:42:57 by sledz

I'm writing an perl script which should communicate over a serial
port. The script should be able to run in Linux and Win32
environments. In both environments exist modules to access the serial
port:

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

Report this message

#2: Re: use modules OS dependent

Posted on 2008-04-14 15:22:13 by Gunnar Hjalmarsson

sledz@dresearch.de wrote:
> I'm writing an perl script which should communicate over a serial
> port. The script should be able to run in Linux and Win32
> environments. In both environments exist modules to access the serial
> port:
>
> 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?

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

Report this message

#3: Re: use modules OS dependent

Posted on 2008-04-14 15:40:24 by sledz

On 14 Apr., 15:22, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> I don't know about "right", but this is one way:
> ...

Thanx Gunnar. That was the solution. And sorry for my impatience. ;-)

Report this message

#4: Re: use modules OS dependent

Posted on 2008-04-16 00:35:23 by Petr Vileta

Gunnar Hjalmarsson wrote:
> sledz@dresearch.de wrote:
>> I'm writing an perl script which should communicate over a serial
>> port. The script should be able to run in Linux and Win32
>> environments. In both environments exist modules to access the serial
>> port:
>>
>> 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:
>>

<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>

Report this message