in reply to Conditionally including modules
Your choices are:
The if module (available in 5.6.2 and later, or from CPAN). Any variables used must be available at compile time (which is true for $^O).
Require/import instead of use. This has the drawback of not happening at compile time, which may subtly change how code that uses things that are imported gets compiled. If the module in question is purely OO, there won't be any imports, so this won't be an issue (and the import statement can be omitted).use if $^O =~ /Win/, "Win32::DriveInfo";
Same as above, but in a BEGIN block; this has the same effect as using "if", but will work on stock 5.6.1 and older:if ($^O =~ /Win/) { require Win32::DriveInfo; import Win32::DriveInfo; }
BEGIN { if ($^O =~ /Win/) { require Win32::DriveInfo; import Win32::DriveInfo; } }
|
|---|