Same perl source for windows and linux

Discussion in 'Perl Misc' started by transam, Jun 14, 2005.

  1. transam

    transam Guest

    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.
    transam, Jun 14, 2005
    #1
    1. Advertising

  2. 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
    Reinhard Pagitsch, Jun 14, 2005
    #2
    1. Advertising

  3. transam

    Guest

    transam <> 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
    , Jun 14, 2005
    #3
  4. transam

    Anno Siegel Guest

    transam <> 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
    Anno Siegel, Jun 14, 2005
    #4
  5. transam

    thundergnat Guest

    Anno Siegel wrote:
    > transam <> 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{
    .....
    }
    thundergnat, Jun 14, 2005
    #5
  6. transam

    Anno Siegel Guest

    thundergnat <> 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
    Anno Siegel, Jun 14, 2005
    #6
  7. transam

    transam Guest

    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
    transam, Jun 15, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    672
  2. Yves Petinot
    Replies:
    9
    Views:
    273
    Brian McCauley
    Jun 30, 2004
  3. Krishna Chaitanya
    Replies:
    1
    Views:
    129
    Krishna Chaitanya
    Feb 27, 2009
  4. Dilbert
    Replies:
    0
    Views:
    824
    Dilbert
    Nov 10, 2011
  5. Replies:
    17
    Views:
    71
    Rustom Mody
    May 22, 2014
Loading...

Share This Page