Others have answered the direct question. I liked broquaint's solution best because, instead of trapping an error in an eval, it just makes a decision based on the OS.

Just one other thought though. It seems that if you continue down this road you're going to have a lot of "if ( $^O =~ /^Win/ ) {...} else {...}" logic scattered throughout the program. It may be advantageous to write a module that handles all this for you. The module would serve as an OS-independant wrapper interface that inherits from the OS-dependant modules you're using. Here's what I was thinking: (Warning, this is untested pseudocode):

package UniWin; BEGIN { if ( $^O =~ /^MSWin/ ) { require Win32::Setupsup; import Win32::Setupsup; @ISA = qw/Win32::Setupsup/; } else { require Expect; import Expect; @ISA = qw/Expect/; } } # Here you write a OS-generic wrapper around any OS # specific uses of Win32::Setupsup and Expect. # For example, if Setupsup has a "Win_This()" method and # Expect has a "Unix_This()" method, you would write a # wrapper called This() which invokes either method # depending on which OS you're using... 1; package main; use strict; use warnings; use UniWin; # ..........The rest of the program goes here...

This has the advantage of creating an OS-generic interface to whichever module you ended up loading in an OS-dependant fashion. That will allow the remainder of your code to concentrate on just doing things one way.

That's just a thought...


Dave


In reply to Re: How can I include a module for Windows only?? by davido
in thread How can I include a module for Windows only?? by pijush

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.