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

Kludge, alternate, but seems that Ubuntu may ("MAY!") prefer this syntax, which works on both MSWin7 (64) and Ubuntu 14.04 and produces the expected output:

# 1159936 revising stevieb's OP use if ( $^O !~ /MSWin/ ), 'Proc::Daemon'; { print "$INC{'Proc/Daemon.pm'}\n"; } use if ($^O =~ /MSWin/), 'Win32::Daemon'; { print "$INC{'Win32/Daemon.pm'}\n"; } exit;
If you didn't program your executable by toggling in binary, it wasn't really programming!

Replies are listed 'Best First'.
Re^2: Problem with ``use if COND, Some::Module'' on Linux
by 1nickt (Canon) on Apr 08, 2016 at 18:02 UTC

    That doesn't fix the problem on my Ubuntu (or Darwin):

    $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS Release: 14.04 Codename: trusty
    Code:
    use if ( $^O !~ /MSWin/ ), 'Proc::Daemon'; { print "$INC{'Proc/Daemon.pm'}\n"; } use if ($^O =~ /MSWin/), 'Win32::Daemon'; { print "$INC{'Win32/Daemon.pm'}\n"; } exit;
    Output:
    Too few arguments to 'use if' (some code returning an empty list in li +st context?) at /home/vagrant/perl5/perlbrew/perls/perl-5.16.3/lib/5. +16.3/if.pm line 7.


    The way forward always starts with a minimal test.
Re^2: Problem with ``use if COND, Some::Module'' on Linux
by stevieb (Canon) on Apr 08, 2016 at 18:04 UTC

    Update: I was mistaken. I didn't test both conditions... the latter one did break.

    Thanks ww, I honestly could have sworn that I tested that, but I couldn't have, as wrapping the condition within parens does in fact work properly.

      Really? On Ubuntu 14.04? Not for me ...

      The way forward always starts with a minimal test.