At 10:38 AM -0700 4/17/02, Bill Becker wrote:
>What would be the best way to determine this programmatically ???

Besides modules like File::Spec, in many cases, you can use Perl's OS 
name variable, or peak into Perl's '\n' newline construct, which I 
prefer.

Perl's special variable $^O (that's the letter 'Oh') has a name for 
the OS, so you can test it for matches against known OS names. IIRC, 
Mac pre-OS X always has 'mac' in it. Perl running under OS X returns 
'darwin'. Try it out in the various systems on which you use Perl, to 
see what to match.

That's still a little indeterminate, isn't it?

So I prefer to take advantage of Perl's "\n" construct, which uses 
the newline native to the OS Perl's executing under:

my $SEP = "\n" eq "\012" ?     '/' :   # *N*X
           "\n" eq "\015" ?     ':' :   # Mac
          "\n" eq "\015\012" ? '/' :   # DOS/Win
                                '/' ;   # default

This works even if you've changed the input & output line separators, 
$/ and $\.

There are other OSes, and other end-of-line combos, so you might have 
to modify these. Some would use '\' as the separator under some 
dos/win regimes.

With a little care about path separators and newlines, you can make 
most Perl scripts agnostic with respect to OS.

HTH

1;

>>
>>  In OS X, Perl is uses the UNIX path separator, '/', instead of Mac's ':'.
>>
>>  Also, paths are UNIX-style. If you use BBEdit, open the script or
>>  file in question, and get the path from the toolbar button. That'll
>>  give you an example to follow.
>>

-- 

   - Bruce

__bruce_van_allen__santa_cruz_ca__

Reply via email to