loading a module dependant on the OS

Discussion in 'Perl Misc' started by Guest, Jun 30, 2003.

  1. Guest

    Guest Guest

    I have a Perl script which runs under Windows and uses the module
    Win32::process, I now have a need to run this on Linux.

    I can do produce two scripts on for each platform, which would be a pain to
    maintane.

    My question being how can I have a script on Linus that has

    use Win32::process;

    since this module does not exist I get a compilation error. I thought I
    could use the $^O variable but my little knowledge fails to supply the
    answer.

    I assume this is a common problem so will have an answer. If you can point
    me in the direction of a README or HOW_TO document I would be greatful.

    Richard.
    Guest, Jun 30, 2003
    #1
    1. Advertising

  2. <> writes:

    > use Win32::process;
    >
    > since this module does not exist I get a compilation error. I thought I
    > could use the $^O variable but my little knowledge fails to supply the
    > answer.


    Since you have a question about use please read at least the first
    paragraph of:

    perldoc -f use

    Write the "use" out long-hand and then apply the knowledge already
    have. That should supply the answer.

    Surely this should be in the FAQ!

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley, Jun 30, 2003
    #2
    1. Advertising

  3. <> thus wrote:
    > use Win32::process;
    >
    > since this module does not exist I get a compilation error. I thought I
    > could use the $^O variable but my little knowledge fails to supply the
    > answer.
    >


    You can do an "eval" before the use.

    Look at this example:
    <code>
    $useReadKey = 0;
    eval q/use Term::ReadKey/;
    if (!$@) {
    # Term-ReadKey module is installed
    $useReadKey = 1;
    }
    </code>

    --
    arc_of_descent
    Rohan Romanus Almeida, Jun 30, 2003
    #3
  4. wrote:
    >
    > use Win32::process;
    >
    > since this module does not exist I get a compilation error. I
    > thought I could use the $^O variable


    You can:

    BEGIN { require Win32::process if $^O eq 'MSWin32' }

    / Gunnar

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jun 30, 2003
    #4
  5. Guest

    Guest Guest

    Thanks for the solution :) I forgot all about eval.

    Richard.


    "Rohan Romanus Almeida" <> wrote in message
    news:...
    >
    > <> thus wrote:
    > > use Win32::process;
    > >
    > > since this module does not exist I get a compilation error. I thought I
    > > could use the $^O variable but my little knowledge fails to supply the
    > > answer.
    > >

    >
    > You can do an "eval" before the use.
    >
    > Look at this example:
    > <code>
    > $useReadKey = 0;
    > eval q/use Term::ReadKey/;
    > if (!$@) {
    > # Term-ReadKey module is installed
    > $useReadKey = 1;
    > }
    > </code>
    >
    > --
    > arc_of_descent
    >
    Guest, Jun 30, 2003
    #5
  6. Guest

    Guest Guest

    Oh wow that was so easy, thanks.

    I'll go read the camel book again.

    Richard.

    "Gunnar Hjalmarsson" <> wrote in message
    news:bdph9k$tpcot$...
    > wrote:
    > >
    > > use Win32::process;
    > >
    > > since this module does not exist I get a compilation error. I
    > > thought I could use the $^O variable

    >
    > You can:
    >
    > BEGIN { require Win32::process if $^O eq 'MSWin32' }
    >
    > / Gunnar
    >
    > --
    > Gunnar Hjalmarsson
    > Email: http://www.gunnar.cc/cgi-bin/contact.pl
    >
    Guest, Jun 30, 2003
    #6
    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. Michael Tonelli

    image dependant on resolution

    Michael Tonelli, Jul 21, 2004, in forum: HTML
    Replies:
    11
    Views:
    680
    Andy Dingley
    Jul 23, 2004
  2. KiwiBrian

    Dependant files query

    KiwiBrian, Oct 15, 2004, in forum: HTML
    Replies:
    2
    Views:
    446
    Toby Inkster
    Oct 16, 2004
  3. Bas
    Replies:
    2
    Views:
    5,916
    Roedy Green
    May 4, 2006
  4. Jeff Smith
    Replies:
    1
    Views:
    301
    Jeff Smith
    Jul 29, 2004
  5. Brian van den Broek
    Replies:
    3
    Views:
    823
    Jeremy Bowers
    Apr 3, 2005
Loading...

Share This Page