2

我想使用 Perl 显示我的计算机的操作系统。我认为以下会做

#!/usr/bin/perl
use strict;
use warnings;

my $os = $^O;
print "$os\n";

但我得到的输出是

linux

我希望输出显示为

Windows XP

这个怎么做?请帮忙。提前致谢。

4

3 回答 3

6

使用POSIX 模块为您提供的uname()函数。

于 2013-03-24T19:10:23.677 回答
2

所有 Perl 发行版都带有Config模块。这个模块有点摇摇晃晃,因为它导入了 hash %Config,但它是一种访问各种 Perl 配置信息的简单方法。

use Config;  # This exports a %Config hash

print "My OS is $Config{osname}\n";
print "My OS version is $Config{osvers}\n";
print "My Architecture Family is $Config{archname}\n";

#
# Print out all of the keys, and see which one looks like one
# you can use. "ld" is actually a rather nice value
#
for my $key (sort keys %Config) {
    no warnings qw(uninitialized); # Some elements have undef values
    print qq($key: "$Config{$key}"\n);
}
于 2013-03-24T21:36:13.100 回答
1

您是否正在寻找

use CGI                 qw( );
use HTTP::BrowserDetect qw( );

my $cgi = CGI->new();
print $cgi->header('text/plain');

my $bd = HTTP::BrowserDetect->new($cgi->user_agent());
print $bd->os_string(), "\n";
于 2013-03-25T07:11:14.483 回答