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

[MacPerl] Re: Re: Using NetPresenz and MacPerl



"Patton, Paul B (MN10)" <Paul.B.Patton@hbc.honeywell.com>
writes a message received Date: 15 Nov 1996 20:20:20 -0600

!Michael Mogitz wrote:
!>Hi - I have been using MacPerl for about a year to check cgi scripts before
!>uploading them on our unix server for production use. Usually I can do a
!>good job of testing and debugging on the mac. One of the tricks I use is to
!>just set a variable like $onMac and if it's true, I set the environment
!>variables that I will be using in the cgi.
!
!
!It would be nice if Perl had a portable way to detect the platform that
!it is running on.  Maybe there is a good way and I just don't know it.
!
!Here's the trick that I came up with originally:
!    
!    $on_unix = $<;      # When running in test mode on the Mac, the PID
!                        # will be zero; it will never be zero on Unix.
!    
!    if ( $on_unix ) {
!        require 'cgi-lib.pl';
!        # etc. etc.
!    }
!
!However, I hope that a future Mac might actually have a non-zero
!process ID (preemptive multitasking! yes!) so what I'm using now is:
!                                
!    if ( $0 =~ /Macintosh HD/ ) {  # Test for something unique in where the
!                                   # script resides on the Mac.
!        $on_mac = 1;
!    }
!
!
!   -Paul-           paul.b.patton@hbc.honeywell.com

There are at least three hooks into the OS without asking the OS directly (via 
say C<system()> calls or backticks).

The simplest is to use the $^O variable, as in:

   if ($^O =~ /MacOS/) { print "It is a Mac!\n"; }
   else {print "it is a $^O\n"; }

With slightly more overhead (loading the full %Config hash) 
try C<use Config;> as in:

  use Config;

  print "this os is $Config{osname}\n";

Another stategy is to look at the directory separators in the @INC array ("/" 
for all unix & VMS, "\" for DOS, ":" for Mac).

Good luck.

Peter Prymmer