in reply to Re: How to have OS specific code sections in Perl
in thread How to have OS specific code sections in Perl

Actually unfortunately I spoke to soon, the code now works fine in Windows (no errors anymore) but now I get an error in Linux:

Undefined subroutine &MIDI::ALSA::client called at ./test.pl line 15

It looks like the 'use if' line needs some more tweaking to work correctly, but how?
  • Comment on Re^2: How to have OS specific code sections in Perl

Replies are listed 'Best First'.
Re^3: How to have OS specific code sections in Perl
by tobyink (Canon) on Oct 31, 2012 at 18:44 UTC

    The problem is that the conditional block is only evaluated at run time, by which time it's too late for use if.

    You want:

    my $LINUX; BEGIN { $LINUX = ($^O eq 'linux') }; use if $LINUX, 'MIDI::ALSA' => ('SND_SEQ_EVENT_PORT_UNSUBSCRIBED', 'SN +D_SEQ_EVENT_SYSEX');

    Or better:

    use if ($^O eq 'linux'), 'MIDI::ALSA' => ('SND_SEQ_EVENT_PORT_UNSUBSCR +IBED', 'SND_SEQ_EVENT_SYSEX');
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^3: How to have OS specific code sections in Perl
by Anonymous Monk on Nov 01, 2012 at 00:56 UTC