in reply to Re: Modules and crossplatform code
in thread Modules and crossplatform code

Updated to include correction (see below).

Or, if you have to use earlier versions of perl which don't have the "if" module in core, you could do the equivalent:

BEGIN { # need this to happen at compile time if ( $^O =~ /whatever/ ) { require Win32::OLE; eval { Win32::OLE->import(); }; } }

@JavaFan: Thanks for the correction. I learned something today. I was aware of the difference between require and use, but I was under the mistaken impression that it wouldn't be important inside a BEGIN block. I chose use so that I wouldn't have to invoke import() explicitly.

Replies are listed 'Best First'.
Re^3: Modules and crossplatform code
by JavaFan (Canon) on Dec 07, 2010 at 13:00 UTC
    That's not equivalent.
      please explain your assertion.

        See use and require and also test your code (modified to be "cross-platform").

        BEGIN { # need this to happen at compile time if ( $^O =~ /some_os_that_does_not_exist/ ) { use SomeOSThatDoesNotExist::Facility; } }