On Thu, 12 Jul 2001 14:59:34 +0900, Nobumi Iyanaga wrote:
>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 "/".
The module File::Spec is written especially for this. But, IMO it is a
bit awkward to use, and may feel like overkill.
Here's the part in File::Spec that makes the distinction:
my %module = (MacOS => 'Mac',
MSWin32 => 'Win32',
os2 => 'OS2',
VMS => 'VMS',
epoc => 'Epoc');
my $module = $module{$^O} || 'Unix';
What, no DOS? ;-)
But, as you can see: check the value of the variable $^O. If it is
"MacOS", then you're on a Mac; if it's "MSWin32", then you're on
Windows, and apart from those others you don't seem to be interested in,
the rest is Unix.
Oh, and there's hardly a need to distinguish between Windows and Unix.
"/" works on Windows too, internally in Perl, that is. For calling
external programs using `...` or system(), you may need backslashes.
--
Bart.