Subject: | Minor error in function is_disjoint |
Hello Jarkko,
I've found a tricky bug in Set::Scalar, function is_disjoint. The bug takes effect only under specific conditions: when is_disjoint() is called in list context, and the compare result is 'disjoint' (not 'disjoint universes'), function return list consisting of a single undef element. While this may be easily avoided by not callinng the function in list context, sometimes list context is more convenient.
Code example is:
my $set1 = Set::Scalar->new( qw( a b));
my $set2 = Set::Scalar->new( qw( c d));
my ( $should_be_true_1, $should_be_true_2) = ( $set1 -> is_disjoint( $set2), 1);
print $should_be_true_1 ? 'OK' : 'ERROR',"\n";
Suggested patch 'Base.pm.patch' is:
*** Base.pm.orig Sat Oct 04 18:46:42 2003
--- Base.pm Sun Mar 28 18:27:05 2004
***************
*** 494,501 ****
sub is_disjoint {
my $a = shift;
my $b = shift;
!
! return $a->compare($b) =~ /^disjoint( universes)?$/;
}
sub is_equal {
--- 494,500 ----
sub is_disjoint {
my $a = shift;
my $b = shift;
! return scalar($a->compare($b) =~ /^disjoint( universes)?$/);
}
sub is_equal {
Sincerelely, Alexei.
P.S.
My environment is: MS Windows XP, Perl 5.8.0.
(Yet the environment seem to be insignificant).