Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How to have OS specific code sections in Perl

by perltux (Scribe)
on Oct 31, 2012 at 18:00 UTC ( #1001724=note: print w/ replies, xml ) Need Help??


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
Re^3: How to have OS specific code sections in Perl
by tobyink (Abbot) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001724]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-07-04 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls