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

" ... (some code returning an empty list in list context?) ... "

Nothing to do with Proc::Daemon, but with the pattern match that returns an empty list:

use strict; use warnings; use if scalar ( $^O !~ /Win32/ ), 'Proc::Daemon'; use if scalar ( $^O =~ /Win32/ ), 'Win32::Daemon'; print $INC{'Proc/Daemon.pm'}; exit; __END__
Output:
perl 1159936.pl /Users/nick/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Proc +/Daemon.pm

Hope this helps!

Updated: force scalar context so we can keep pattern matches


The way forward always starts with a minimal test.

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

    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.

      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

      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?

      Updated to force scalar context on the pattern match output.

      The way forward always starts with a minimal test.