in reply to Conditionally including modules

my $hostOs = $^O; if ($hostOS eq "MSWin32") { require moduleName; }
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Replies are listed 'Best First'.
Re^2: Conditionally including modules
by Tanktalus (Canon) on Apr 04, 2005 at 16:06 UTC

    And here's why this is the best choice at the time I wrote it: require is faster than eval STR. In addition, Win32::DriveInfo (according to its documentation) doesn't export anything anyway.

    Personally, I use require over use more that most people here, it seems - but fully qualified names don't bother me as they do some.

    Alternately, you could just always load Win32::DriveInfo:

    my $hasdriveinfo = eval { require Win32::DriveInfo; 1 };
    This will fail gracefully on Unix, but load the module on Windows. The only downside is if Win32::DriveInfo isn't installed on Windows, and you absolutely must use it on Windows. Then you'll need to check:
    if ($^O eq 'MSWin32' and not $hasdriveinfo) { die "failed to load Win32::DriveInfo - is it installed? $@"; }
    At this point, jbrugger's answer is way simpler, if you do really need it.