At 14:59 Uhr +0900 12.07.2001, Nobumi Iyanaga wrote:
>Hello,
>
>I am writing some scripts for cross-platform use.  How can I determine the OS on 
>which a script is running?  If it is a Mac, I will use ":" as directory separator; if 
>it is a Windows, I will use "\\", and if it is a Unix, I will use "/".
>
>Thank you in advance!
>
>Nobumi Iyanaga
>Tokyo,
>Japan

It's possible to do a

    if ($^O eq 'MacOS') {
        ...
    } elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' ) {
        ...
    } else {
        ...
    }

but you'd better don't do that. It's always better to use File::Spec, when you need to 
specify directory or file pathes on different platforms. Take a look at File::Spec, 
File::Spec::Mac, File::Spec::Win32, File::Spec::Unix for details. However, be aware of 
(even with File::Spec): A relative path on MacOS should have a leading ':', while 
that's not true on the other two platforms, MacOS has the concept of volumes, Unix has 
not, the equivalent of ../../dir on Unix is :::dir, the equivalent of ./dir is :dir 
etc. etc.


Best regards,

--Thomas


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to