Examine the $^O
variable which will contain the name of the operating system:
print "$^O
";
Which prints linux
on Linux and MSWin32
on Windows.
You can also refer to this variable by the name $OSNAME
if you use the English module:
use English qw' -no_match_vars ';
print "$OSNAME
";
According to perlport, $^O
will be darwin
on Mac OS X.
You can also use the Config core module, which can provide the same information (and a lot more):
use Config;
print "$Config{osname}
";
print "$Config{archname}
";
Which on my Ubuntu machine prints:
linux
i486-linux-gnu-thread-multi
Note that this information is based on the system that Perl was built, which is not necessarily the system Perl is currently running on (the same is true for $^O
and $OSNAME
); the OS won't likely be different but some information, like the architecture name, may very well be.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…