Same perl source for windows and linux

T

transam

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

Reinhard Pagitsch

Hello,
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
 
A

axel

transam said:
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
 
A

Anno Siegel

transam said:
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
 
T

thundergnat

Anno said:
"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{
.....
}
 
A

Anno Siegel

thundergnat said:
Anno Siegel wrote:

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
 
T

transam

Reinhard,

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

Regards: tr.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top