![]() |
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. |
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 |
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 |
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 |
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{ ..... } |
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 |
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:40 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.