[Koha-patches] [PATCH] kohabug 2345: bad comparisons pervade reports

Galen Charlton galen.charlton at liblime.com
Thu Jul 31 15:06:30 CEST 2008


Hi Paul,

On Thu, Jul 31, 2008 at 7:37 AM, paul POULAIN <paul.poulain at biblibre.com> wrote:
> Jesse Weaver a écrit :
>> This patch changes all $foo eq undef's to !defined($foo). It also makes misc/spellcheck_suggest/build_spellcheck_suggest.pl have proper syntax.
>>
> Just a quick question : is this change made because :
...
> - the previous code is considered poor in Perl officially ?

Bingo.  The proper way to test whether a scalar has an undefined value
is by use of the defined() function; 'eq' is for string comparisons,
and if warnings are enabled, Perl will complain if one side or the
other of the comparison is undefined.

Run the following script and see the warnings:

#!/usr/bin/perl

use strict;
use warnings;

my $foo; # starts out undef
if ($foo eq undef) {
    print "\$foo is undef\n";
}

Now imagine what would happen if we (as we should) turn on warnings in
Koha.  I'll make a proper 3.2 RFC for it shortly, but IMO we really
need to start putting in 'use warnings' in a all scripts.  Many bugs
have already been fixed that were based on undef scalars that should
have had a value, and many more undoubtedly lurk.

Regards,

Galen
-- 
Galen Charlton
VP, Research & Development, LibLime
galen.charlton at liblime.com
p: 1-888-564-2457 x709
skype: gmcharlt



More information about the Koha-patches mailing list