问题
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.
This has led me to wonder how a Perl script might detect under which of these flavours it is running.
回答1:
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";
}
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.
回答2:
You can examine how both perls have been compiled with
perl -V
Once you find what difference is causing your problem, you can detect specific feature using Config package. To list all settings:
perl -MConfig -MData::Dump -e "dd \%Config"
回答3:
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. At least Strawberry Perl 5.20.1 does not. You can use code similar to the following to figure out whether or not your script is being run through 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.
来源:https://stackoverflow.com/questions/5256901/can-a-perl-script-detect-whether-its-running-under-activestate-vs-strawberry-pe