Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Same perl source for windows and linux (http://www.velocityreviews.com/forums/t892835-same-perl-source-for-windows-and-linux.html)

transam 06-14-2005 09:03 AM

Same perl source for windows and linux
 
Dear perl friends,

I have a project, that uses fifo-s (named pipes) on linux and on
windows. Since the piping mechanism is very different on linux and on
windows, I have different braches for piping.

The code looks:
if($^O ne "linux"){
use WIN32:Pipe;
WPipe = WIN32:Pipe(...
..)
}
else{
fifo = mkfifo(...);
fp = open(FIFO, ...);
read ...
write ...
}

In windows case this works well.
On linux I get errors both for the
use clause, saying, it is not found, and
for the usage of the WIN32:Pipe class saying,
the usage is illegal in that form.

Is there a way to tell perl, it should not
do any syntax check on windows code?
Or any other solution (except of using different
sources, that I do at the moment).

Thanks in advance, tr.


Reinhard Pagitsch 06-14-2005 10:11 AM

Re: Same perl source for windows and linux
 
Hello,

transam wrote:
> Dear perl friends,
>
> I have a project, that uses fifo-s (named pipes) on linux and on
> windows. Since the piping mechanism is very different on linux and on
> windows, I have different braches for piping.
>
> The code looks:
> if($^O ne "linux"){
> use WIN32:Pipe;
> WPipe = WIN32:Pipe(...
> ..)
> }
> else{
> fifo = mkfifo(...);
> fp = open(FIFO, ...);
> read ...
> write ...
> }
>
> In windows case this works well.
> On linux I get errors both for the
> use clause, saying, it is not found, and
> for the usage of the WIN32:Pipe class saying,
> the usage is illegal in that form.
>
> Is there a way to tell perl, it should not
> do any syntax check on windows code?
> Or any other solution (except of using different
> sources, that I do at the moment).
>
> Thanks in advance, tr.
>


Try the following:

eval {
require WIN32::Pipe;
}

if ($@) {
# Error => Modul not installed
} else {

# Modul installed

}


regards,
Reinhard

axel@white-eagle.invalid.uk 06-14-2005 10:32 AM

Re: Same perl source for windows and linux
 
transam <transam45@gmx.net> wrote:
> I have a project, that uses fifo-s (named pipes) on linux and on
> windows. Since the piping mechanism is very different on linux and on
> windows, I have different braches for piping.


> The code looks:
> if($^O ne "linux"){
> use WIN32:Pipe;
> WPipe = WIN32:Pipe(...
> ..)
> }
> else{
> fifo = mkfifo(...);
> fp = open(FIFO, ...);
> read ...
> write ...
> }


> In windows case this works well.
> On linux I get errors both for the
> use clause, saying, it is not found, and
> for the usage of the WIN32:Pipe class saying,
> the usage is illegal in that form.


Because the format of the name is incorrect for a start - a double colon
'::' should separate package identifiers, not a single colon.

But since you are not posting real code it is a bit difficult to tell
what else might be wrong.

Axel


Anno Siegel 06-14-2005 11:22 AM

Re: Same perl source for windows and linux
 
transam <transam45@gmx.net> wrote in comp.lang.perl.misc:
> Dear perl friends,
>
> I have a project, that uses fifo-s (named pipes) on linux and on
> windows. Since the piping mechanism is very different on linux and on
> windows, I have different braches for piping.
>
> The code looks:
> if($^O ne "linux"){
> use WIN32:Pipe;


"if" happens at run time. It has no effect on "use ...", which happens
(unconditionally) at compile time. Try require() (plus a call to ->import,
if needed).

Anno

thundergnat 06-14-2005 01:03 PM

Re: Same perl source for windows and linux
 
Anno Siegel wrote:
> transam <transam45@gmx.net> wrote in comp.lang.perl.misc:
>
>>Dear perl friends,
>>
>>I have a project, that uses fifo-s (named pipes) on linux and on
>>windows. Since the piping mechanism is very different on linux and on
>>windows, I have different braches for piping.
>>
>>The code looks:
>>if($^O ne "linux"){
>> use WIN32:Pipe;

>
>
> "if" happens at run time. It has no effect on "use ...", which happens
> (unconditionally) at compile time. Try require() (plus a call to ->import,
> if needed).
>
> Anno



Or, you could use the "if" pragma.


if($^O =~ /Win/){ # Changed so that Darwin,VMS,BDS,etc. users wouldn't get a suprise.
use if ($^O =~ /Win/), 'WIN32:Pipe';
WPipe = WIN32:Pipe(.....)
}
else{
.....
}

Anno Siegel 06-14-2005 01:17 PM

Re: Same perl source for windows and linux
 
thundergnat <thundergnat@hotmail.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:


> > "if" happens at run time. It has no effect on "use ...", which happens
> > (unconditionally) at compile time. Try require() (plus a call to ->import,
> > if needed).

>
> Or, you could use the "if" pragma.
>
> if($^O =~ /Win/){ # Changed so that Darwin,VMS,BDS,etc. users wouldn't
> get a suprise.
> use if ($^O =~ /Win/), 'WIN32:Pipe';
> WPipe = WIN32:Pipe(.....)
> }
> else{
> .....
> }


Ah, that's nice. I hadn't noticed...

Anno

transam 06-15-2005 08:24 AM

Re: Same perl source for windows and linux
 
Reinhard,

Thanks, that works well for me.
Also thanks for the other tips.

Regards: tr.

Reinhard Pagitsch wrote:
> Hello,
>
> transam wrote:
> > Dear perl friends,
> >
> > I have a project, that uses fifo-s (named pipes) on linux and on
> > windows. Since the piping mechanism is very different on linux and on
> > windows, I have different braches for piping.
> >
> > The code looks:
> > if($^O ne "linux"){
> > use WIN32:Pipe;
> > WPipe = WIN32:Pipe(...
> > ..)
> > }
> > else{
> > fifo = mkfifo(...);
> > fp = open(FIFO, ...);
> > read ...
> > write ...
> > }
> >
> > In windows case this works well.
> > On linux I get errors both for the
> > use clause, saying, it is not found, and
> > for the usage of the WIN32:Pipe class saying,
> > the usage is illegal in that form.
> >
> > Is there a way to tell perl, it should not
> > do any syntax check on windows code?
> > Or any other solution (except of using different
> > sources, that I do at the moment).
> >
> > Thanks in advance, tr.
> >

>
> Try the following:
>
> eval {
> require WIN32::Pipe;
> }
>
> if ($@) {
> # Error => Modul not installed
> } else {
>
> # Modul installed
>
> }
>
>
> regards,
> Reinhard




All times are GMT. The time now is 06:58 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.