Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
use modules OS dependent
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sl...@dresearch.de  
View profile  
 More options Apr 14 2008, 8:42 am
Newsgroups: comp.lang.perl.modules
From: sl...@dresearch.de
Date: Mon, 14 Apr 2008 05:42:57 -0700 (PDT)
Local: Mon, Apr 14 2008 8:42 am
Subject: use modules OS dependent
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gunnar Hjalmarsson  
View profile  
 More options Apr 14 2008, 9:22 am
Newsgroups: comp.lang.perl.modules
From: Gunnar Hjalmarsson <nore...@gunnar.cc>
Date: Mon, 14 Apr 2008 15:22:13 +0200
Local: Mon, Apr 14 2008 9:22 am
Subject: Re: use modules OS dependent

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sl...@dresearch.de  
View profile  
 More options Apr 14 2008, 9:40 am
Newsgroups: comp.lang.perl.modules
From: sl...@dresearch.de
Date: Mon, 14 Apr 2008 06:40:24 -0700 (PDT)
Local: Mon, Apr 14 2008 9:40 am
Subject: Re: use modules OS dependent
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. ;-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jürgen Exner  
View profile  
 More options Apr 14 2008, 9:59 am
Newsgroups: comp.lang.perl.modules
From: Jürgen Exner <jurge...@hotmail.com>
Date: Mon, 14 Apr 2008 13:59:09 GMT
Local: Mon, Apr 14 2008 9:59 am
Subject: Re: use modules OS dependent

sl...@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 );

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gunnar Hjalmarsson  
View profile  
 More options Apr 14 2008, 10:13 am
Newsgroups: comp.lang.perl.modules
From: Gunnar Hjalmarsson <nore...@gunnar.cc>
Date: Mon, 14 Apr 2008 16:13:10 +0200
Local: Mon, Apr 14 2008 10:13 am
Subject: Re: use modules OS dependent

Jürgen Exner wrote:
> sl...@dresearch.de wrote:
>> 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.

     s/without/with/

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Petr Vileta  
View profile  
 More options Apr 15 2008, 6:35 pm
Newsgroups: comp.lang.perl.modules
From: "Petr Vileta" <sto...@practisoft.cz>
Date: Wed, 16 Apr 2008 00:35:23 +0200
Local: Tues, Apr 15 2008 6:35 pm
Subject: Re: use modules OS dependent

Gunnar Hjalmarsson wrote:
> sl...@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>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »