[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Portable code

> I ported my program to the Mac and got it working, and then wrapped up the
> Mac specific stuff in a
> if ( $^O =~ /macos/i ) { Mac code }
> block.  But when I move it to a UNIX box, the Mac 'use MacModule;'
> statements cause the program to die ('cause the UNIX box is missing them).
> How do I hide them from the interpreter when the program isn't running on
> a Mac?

I just wrote this:

  foreach (qw(TheModule Data::Dumper Mac::Nonexistent Mac::Windows)) {
    $MOD_AVAIL{$_} = eval "use $_; 1";

Put it at the top of your program and put the modules you want inside
the qw() list. The hash %MOD_AVAIL will tell you whether a particular
module has been loaded.

 Kevin Reid: |    Macintosh:      
  "I'm me."  | Think different.

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org