[vox-tech] perl question: how to detect operating system?

Jim Angstadt vox-tech@lists.lugod.org
Mon, 24 Dec 2001 11:10:54 -0800 (PST)


--- Peter Jay Salzman <p@dirac.org> wrote:
> in perl, how does one go about detecting what
> operating system the
> program is running under?

---------------------------
#!/perl/bin/perl -w
use strict;
my $OS = '';

# ----- Thanks to the author of CGI.pl -----
#
# FIGURE OUT THE OS WE'RE RUNNING UNDER
# Some systems support the $^O variable.  If not
# available then require() the Config library
unless ($OS) {
    unless ($OS = $^O) {
	require Config;
	$OS = $Config::Config{'osname'};
    }
}

if    ($OS=~/Win/i)     { $OS = 'WINDOWS'; }
elsif ($OS=~/vms/i)     { $OS = 'VMS'; } 
elsif ($OS=~/^MacOS$/i) { $OS = 'MACINTOSH'; }
elsif ($OS=~/os2/i)     { $OS = 'OS2'; }
else  { $OS = 'UNIX'; }

print "The OS is: ", $OS;

----------------------------------

Happy Holidays,
Jim

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com