问题描述
我有一个Perl脚本仍在尝试调试,在此过程中,我注意到它在ActivePerl和Strawberry Perl下运行的方式有所不同。
I have a Perl script I'm still trying to debug and in the process I've noticed that it behaves differently running under ActivePerl and Strawberry Perl.
使我想知道一个Perl脚本如何检测它在哪种口味下运行。
This has led me to wonder how a Perl script might detect under which of these flavours it is running.
推荐答案
在Windows上始终是ActivePerl(或至少由于Perl 5.005)定义了 Win32 :: BuildNumber()
函数,因此您可以在运行时进行检查:
ActivePerl on Windows always (or at least since Perl 5.005) defines the Win32::BuildNumber()
function, so you can check for it at runtime:
if (defined &Win32::BuildNumber) {
say "This is ActivePerl";
}
else {
say "This is NOT ActivePerl";
}
如果您也想在其他平台上检查ActivePerl,则应使用而是使用 ActivePerl :: BUILD()
函数。它仅在ActivePerl 5.8.7内部版本814中引入,因此无法在真正的旧版本中使用。
If you want to check for ActivePerl on other platforms too, then you should use the ActivePerl::BUILD()
function instead. It only got introduced in ActivePerl 5.8.7 build 814, so it won't work on really old releases.
这篇关于Perl脚本能否检测到它是否在Activestate和Strawberry Perl下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!