Scalar::Util and x86_64
Recently (28 June 08), my 64-bit CentOS machine started sending me error reports from cron jobs running perl scripts that had been running fine until now. There was a problem coming from Scalar::Util:
Use of uninitialized value in concatenation (.) or string at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Scalar/Util.pm line 30
I’ve seen this problem before, as on this comp.lang.perl.misc post from Tim Boyer.
A force re-install of the Scalar::Util package in cpan does the trick:
cpan> force install Scalar::Util
However, while looking at Scalar/Util.pm around line 30, I found another bug which was hinted at by the first bug, but still only runs if there really is something to croak about:
Scalar/Util.pm version 1.19 lines 28-31:
if (grep { /^(dualvar|set_prototype)$/ } @_ ) {
require Carp;
Carp::croak("$1 is only available with the XS version");
}
If the array @_ contains either ‘dualvar’ or ‘set_prototype’, croak should be called with $1 filled with the string that matched. Unfortunately, this doesn’t happen. The ‘grep { /pattern/ } @_’ construct returns an array of values from @_ that matches the pattern. The if statement around it is true if the array returned from grep contains at least one element, meaning at least one element in @_ matched the /pattern/. Capturing within this construct does not work outside the { /pattern/ } block, and therefore the $1 will not get filled with the first (or any) string that matched the pattern.
This could be fixed by separating tests, as follows, although there is probably a much sexier way to do it:
if (grep { /^dualvar$/ } @_ {
require Carp;
Carp::croak("dualvar is only available with the XS version");
}
if (grep { /^set_prototype$/ } @_ {
require Carp;
Carp::croak("set_prototype is only available with the XS version");
}
I’ve emailed the author of Scalar::Util to see if this change can be made.
19 July 2008: Update
I found the proper place to report bugs in perl modules available on cpan, which is http://rt.cpan.org. Then I found a previous bug report that was for this exact problem.
It’s at: http://rt.cpan.org/Public/Bug/Display.html?id=31054