且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何判断我的 Perl 脚本是否在 Windows 下运行?

更新时间:2023-09-20 15:39:46

来自 perldoc perlvar代码>:

  • $OSNAME
  • $^O

在配置过程中确定的构建此 Perl 副本的操作系统名称.该值与 $Config{'osname'} 相同.另请参阅 perlrun 中记录的 Config 和 -V 命令行开关.

The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{'osname'}. See also Config and the -V command-line switch documented in perlrun.

在 Windows 平台中,$^O 不是很有用:因为它总是 MSWin32,它不能区分 95/98/ME/NT/2000/XP/CE/.NET.使用 Win32::GetOSName()Win32::GetOSVersion()(参见 Win32perlport) 以区分变体.>

In Windows platforms, $^O is not very helpful: since it is always MSWin32, it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.