in reply to Re^3: require different modules per OS?
in thread require different modules per OS?
You need string-eval, not block-eval.
eval 'use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>0 );' if $ +^O =~ /win32/i;
Or
BEGIN { eval 'use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>0 +);' if $^O =~ /win32/i; }
if you want it to take effect early (before the rest of the code is compiled), like with a normal use.
Also note that the if $^O =~ ... test needs to be outside of the eval. Reason is that use implies a BEGIN {} block, which is being run as soon as it is defined (when the eval'ed code is being compiled), i.e. before an if within the eval would be tested (this is the same reason your original attempt failed, btw).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: require different modules per OS?
by Anonymous Monk on Nov 18, 2009 at 15:32 UTC |