Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I normally load my modules depending if the script runs on Windows or on Mac with the following:

use if $VersionOS eq 'Win', LWP::UserAgent::ProxyAny;

Now I have the quite stupid problem that I need to declare the variables that need to be exported, for example:

use if $VersionOS eq 'Win', Win32::OLE::Const qw( Microsoft.Word);

...which does not work. Any ideas?

Replies are listed 'Best First'.
Re: Load module conditionally and export variables
by haukex (Archbishop) on Jan 29, 2019 at 15:16 UTC

    As documented in if, what comes after the use if is a list (like any other import list). Try e.g. use if $VersionOS eq 'Win', 'Win32::OLE::Const', qw(Microsoft.Word);

      Ohh, that easy. Thank you very much!