in reply to Re: Problem with ``use if COND, Some::Module'' on Linux
in thread Problem with ``use if COND, Some::Module'' on Linux

Yep, that works if I do ne 'MSWin32', but I'm very curious to know why my way works on Windows but not on nix.

The whole reason for the !~, =~ is so I don't have to check for both MSWin32 and MSWin64.

Replies are listed 'Best First'.
Re^3: Problem with ``use if COND, Some::Module'' on Linux
by VinsWorldcom (Prior) on Apr 08, 2016 at 19:41 UTC

    Not for nothing, but is 'MSWin64' an actual OS string? I'm on Windows 7 x64 with Strawberry Perl 5.22 64-bit and $^O still returns "MSWin32" for me.

    VinsWorldcom@C:\Users\VinsWorldcom> ver Microsoft Windows [Version 6.1.7601] VinsWorldcom@C:\Users\VinsWorldcom> perl -v This is perl 5, version 22, subversion 1 (v5.22.1) built for MSWin32-x +64-multi-thread [...] VinsWorldcom@C:\Users\VinsWorldcom> perl -e "print $^O" MSWin32
Re^3: Problem with ``use if COND, Some::Module'' on Linux
by stevieb (Canon) on Apr 08, 2016 at 17:45 UTC

    The following works...

    my $is_win = $^O =~ /MSWin/ ? 1 : 0; use if $is_win, 'Win32::Daemon'; use if ! $is_win, 'Proc::Daemon';
      Do you really need a ternary operator here?

      I would think that:

      my $is_win = $^O =~ /MSWin/;
      works the same way, doesn't it?
        neither version works, my $is_win is undef when "use if" is testing it at compile time
Re^3: Problem with ``use if COND, Some::Module'' on Linux
by 1nickt (Canon) on Apr 08, 2016 at 17:48 UTC

    Updated to force scalar context on the pattern match output.

    The way forward always starts with a minimal test.