简体   繁体   English

Perl脚本可以检测它是否在Activestate vs Strawberry Perl下运行?

[英]Can a Perl script detect whether it's running under Activestate vs 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脚本我还在尝试调试,在这个过程中我注意到它在ActivePerl和Strawberry Perl下的运行方式不同。

This has led me to wonder how a Perl script might detect under which of these flavours it is running. 这让我想知道Perl脚本如何检测它正在运行的这些风格。

You can examine how both perls have been compiled with 您可以检查两个perls是如何编译的

perl -V

Once you find what difference is causing your problem, you can detect specific feature using Config package. 一旦发现导致问题的区别,就可以使用Config包检测特定功能。 To list all settings: 列出所有设置:

perl -MConfig -MData::Dump -e "dd \%Config"

ActivePerl on Windows always (or at least since Perl 5.005) defines the Win32::BuildNumber() function, so you can check for it at runtime: Windows上的ActivePerl总是(或至少从Perl 5.005开始)定义Win32::BuildNumber()函数,因此您可以在运行时检查它:

if (defined &Win32::BuildNumber) {
    say "This is ActivePerl";
}
else {
    say "This is NOT ActivePerl";
}

If you want to check for ActivePerl on other platforms too, then you should use the ActivePerl::BUILD() function instead. 如果你想在其他平台上检查ActivePerl,那么你应该使用ActivePerl::BUILD()函数。 It only got introduced in ActivePerl 5.8.7 build 814, so it won't work on really old releases. 它只在ActivePerl 5.8.7 build 814中引入,所以它不适用于真正的旧版本。

ActiveState Perl since version 813.1 provides the ActivePerl package by default (without requiring to load any module), and other versions of Perl likely do not. 自版本813.1以来的ActiveState Perl默认提供ActivePerl包(无需加载任何模块),而其他版本的Perl可能不会。 At least Strawberry Perl 5.20.1 does not. 至少Strawberry Perl 5.20.1没有。 You can use code similar to the following to figure out whether or not your script is being run through ActiveState Perl: 您可以使用类似于以下内容的代码来确定您的脚本是否通过ActiveState Perl运行:

if (exists $::{'ActivePerl::'}) {
  # getting called through ActiveState Perl
} else {
  # not getting called through ActiveState Perl
}

See http://docs.activestate.com/activeperl/5.8/lib/ActivePerl.html for more information about the ActivePerl module. 有关ActivePerl模块的更多信息,请参见http://docs.activestate.com/activeperl/5.8/lib/ActivePerl.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM