in reply to Odd WMI situation

In order to be effective, the require() has to be executed before the rest of the code is compiled. You can make this happen by putting it (and the conditional that causes it to execute) inside a BEGIN block:

BEGIN { if ( $^O eq =~ m/MSWin32/i ) { ... require Win32::OLE; Win32::OLE->import( qw{ in } ); } }

The BEGIN is unconditionally executed as soon as it finishes compiling, and before anything below it compiles. Note that there is no colon after the BEGIN. If you insert the colon it becomes a labelled block; this is syntactically valid so you don't get an error, but it will not do what you want.

On the other hand, there's always use if ....

Replies are listed 'Best First'.
Re^2: Odd WMI situation
by ikegami (Patriarch) on Jul 09, 2019 at 04:11 UTC

    You might need to add

    else { *in = \∈ }

    to prevent compilation errors depending on the rest of the code (i.e. whether it's called using or without using parens).