4

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.

hippietrail
  • 13,703
  • 15
  • 87
  • 133

3 Answers3

8

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"
bvr
  • 9,599
  • 20
  • 28
  • The only useful difference I could see was that Strawberry Perl puts its own name in `uname` but ActivePerl just has a blank `uname`. This leaves open the possibility that some other Windows Perl could be confused with ActivePerl. Not a perfect situation but perhaps all we have... – hippietrail Mar 10 '11 at 16:15
  • Also `Data::Dump` doesn't seem to be available by default on Strawberry Perl. – hippietrail Mar 11 '11 at 01:56
3

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.

Jan Dubois
  • 176
  • 1
  • 2
1

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.

Louis Strous
  • 734
  • 7
  • 13