Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: How to have OS specific code sections in Perl

by VinsWorldcom (Parson)
on Oct 31, 2012 at 17:03 UTC ( #1001708=note: print w/replies, xml ) Need Help??

in reply to How to have OS specific code sections in Perl

There error is happening because the module MIDI::ALSA is not installed on your Windows machine.

use doesn't work the way you're thinking it does. It is not evaluated as the code is run, but before that. So your "logic" is correct, but your logic is wrong - if that makes sense ;-)

There have been many suggestions on how to do this with the if pragma for example, but I've found this to work for me:

use strict; use warnings; my $HAVE_MIDI_ALSA = 0; eval "use MIDI::ALSA"; if($@) { print "MIDI::ALSA required\n"; exit } else { $HAVE_MIDI_ALSA = 1 } if (($^O eq 'linux') and $HAVE_MIDI_ALSA) { MIDI::ALSA::client('test',1,1,1); MIDI::ALSA::connectfrom(0,'MidiSport 4x4:0'); MIDI::ALSA::connectto(1,'MidiSport 4x4:0'); MIDI::ALSA::start(); }

Replies are listed 'Best First'.
Re^2: How to have OS specific code sections in Perl
by perltux (Scribe) on Oct 31, 2012 at 17:38 UTC
    Thanks for the explanation as to why my logic is wrong. :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001708]
Ratazong takes a cookie from the platter on the sideboard.
Ratazong adds shortbread cookies to the platter on the sideboard.
[Lady_Aleena]: Hi Ratazong.
[Ratazong]: Hi Lady Aleena
Ratazong just learned about free cookies ;-)
shmem rolls a barrel of beer into the refectorium at the request of jedikaiti

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-04-26 10:01 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (471 votes). Check out past polls.