in reply to Re: Conditionally including modules
in thread Conditionally including modules
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:
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:my $hasdriveinfo = eval { require Win32::DriveInfo; 1 };
At this point, jbrugger's answer is way simpler, if you do really need it.if ($^O eq 'MSWin32' and not $hasdriveinfo) { die "failed to load Win32::DriveInfo - is it installed? $@"; }
|
|---|