in reply to conditionally include a module

See use:

It is exactly equivalent to BEGIN { require Module; import Module LIST; }

So, do just that, except possibly without the BEGIN block, if you want to delay the decision further:

# use Win32::OLE; # becomes if ($^O eq 'MSWin32') { # dunno about Cygwin require Win32::OLE; Win32::OLE->Option( Warn => 3 ); # to get quicker/better feedback +on errors };

Replies are listed 'Best First'.
Re^2: conditionally include a module
by ForgotPasswordAgain (Vicar) on Aug 23, 2007 at 10:09 UTC

    Just a little note on top of that. The import is what handles arguments you normally pass to use, so if you do something like:

    use Whatever::Module qw(funky);

    you have to add a Whatever::Module->import(qw(funky)); after your require.