Subject: | Bad code for _isnt_ARRAY_of_scalars, _isnt_HASH_of_scalars |
There are some errors in the definitions for _isnt_ARRAY_of_scalars()
and _isnt_HASH_of_scalars() which lead to "interesting" results... I
discovered this when comparing arrays of objects which have
stringification overloads...
The code in 0.5 is:
sub _isnt_ARRAY_of_scalars {
return 1 if ref ne "ARRAY";
return scalar grep ref, @$_;
}
sub _isnt_HASH_of_scalars {
return 1 if ref ne "HASH";
return scalar grep ref, values %$_;
}
When it should actually be:
sub _isnt_ARRAY_of_scalars {
return 1 if ref $_[0] ne "ARRAY";
return scalar grep ref, @$_{[0]};
}
sub _isnt_HASH_of_scalars {
return 1 if ref $_[0] ne "HASH";
return scalar grep { ref } values %{$_[0]};
}
Note that $_ is not normally defined in the body of a function --
instead of $_ you should use $_[0].