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

Jesse Weaver jesse.weaver at liblime.com
Fri Jul 25 19:32:05 CEST 2008


This patch changes all $foo eq undef's to !defined($foo). It also makes misc/spellcheck_suggest/build_spellcheck_suggest.pl have proper syntax.
---
 cataloguing/addbiblio.pl                           |    2 +-
 misc/cronjobs/holds/build_holds_queue.pl           |    2 +-
 misc/spellcheck_suggest/make_spellcheck_suggest.pl |    6 ++----
 reports/acquisitions_stats.pl                      |    6 +++---
 reports/bor_issues_top.pl                          |    4 ++--
 reports/borrowers_out.pl                           |    2 +-
 reports/borrowers_stats.pl                         |    6 +++---
 reports/cat_issues_top.pl                          |    2 +-
 reports/catalogue_stats.pl                         |    6 +++---
 reports/issues_avg_stats.pl                        |    6 +++---
 10 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index 7713113..f811c83 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -84,7 +84,7 @@ sub MARCfindbreeding {
             }
         }
 		
-        if ( ref($record) eq undef ) {
+        if ( !defined(ref($record)) ) {
             return -1;
         }
         else {
diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl
index 03a275f..e422248 100755
--- a/misc/cronjobs/holds/build_holds_queue.pl
+++ b/misc/cronjobs/holds/build_holds_queue.pl
@@ -152,7 +152,7 @@ sub randarray {
         $rand[$randnum] = shift(@array);
         while (1) {
                 my $randnum = int(rand($seed));
-                if ($rand[$randnum] eq undef) {
+                if (!defined($rand[$randnum])) {
                         $rand[$randnum] = shift(@array);
                 }
                 last if ($#array == -1);
diff --git a/misc/spellcheck_suggest/make_spellcheck_suggest.pl b/misc/spellcheck_suggest/make_spellcheck_suggest.pl
index 96ffea8..097e792 100755
--- a/misc/spellcheck_suggest/make_spellcheck_suggest.pl
+++ b/misc/spellcheck_suggest/make_spellcheck_suggest.pl
@@ -83,7 +83,7 @@ use C4::Context;
  # and uncomment the one after it, adding your site info (check out GRANT
  # syntax in the mysql manual if you're unsure how enable authentication)
 #
-my dbh2 = C4::Context->dbh;
+my $dbh2 = C4::Context->dbh;
 #
 #my $dbh2=DBI->connect("DBI:mysql:<add your database name here>:localhost","<add your mysql user here>","<add your password here>");
 ########################################################################
@@ -97,12 +97,10 @@ my $counter = 0;
 print "Step 1 of 5: Checking to make sure suggest tables exist\n";
 my $check_tables_query = "select distinct resultcount from ?";
 my @tables = ("notdistinctspchk", "notdistinctsugg", "spellcheck", "suggestions");
-my %tables = ( notdistinctspchk => "( display varchar(40) not null default,
-				suggestion varchar(40) not null default,
 foreach my $table (@tables) {
   my $sth_check=$dbh2->prepare($check_tables_query) || die "cant prepare query: $DBI::errstr";
   my $rv = $sth_check->execute($table);
-  if($rv eq undef) {
+  if(!defined($rv)) {
     print "$table missing ... creating it now\n";
     my $create_this = "CREATE TABLE \'$table\' \(
   			display varchar\(40\) NOT NULL default \'\',
diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl
index ce0f37d..93269f0 100755
--- a/reports/acquisitions_stats.pl
+++ b/reports/acquisitions_stats.pl
@@ -656,9 +656,9 @@ sub calculate {
     my $emptycol;
     while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
 		#warn "filling table $row / $col / $value ";
-        $emptycol = 1         if ( $col eq undef );
-        $col      = "zzEMPTY" if ( $col eq undef );
-        $row      = "zzEMPTY" if ( $row eq undef );
+        $emptycol = 1         if ( !defined($col) );
+        $col      = "zzEMPTY" if ( !defined($col) );
+        $row      = "zzEMPTY" if ( !defined($row) );
 
         $table{$row}->{$col}     += $value;
         $table{$row}->{totalrow} += $value;
diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl
index 7761366..f9cf661 100755
--- a/reports/bor_issues_top.pl
+++ b/reports/bor_issues_top.pl
@@ -340,7 +340,7 @@ sub calculate {
 	# 	)
     while (my @data = $dbcalc->fetchrow) {
         my ($row, $rank, $id, $col) = @data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
 		unless ($patrons{$id}) {
 			$patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}};
 		}
@@ -356,7 +356,7 @@ sub calculate {
     $debug and print DEBUG "rows: ", $dbcalc->rows, "\n";
     while (my @data = $dbcalc->fetchrow) {
         my ($row, $rank, $id, $col) = @data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
 		unless ($patrons{$id}) {
 			$patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}};
 		}
diff --git a/reports/borrowers_out.pl b/reports/borrowers_out.pl
index e836017..763fa7e 100755
--- a/reports/borrowers_out.pl
+++ b/reports/borrowers_out.pl
@@ -273,7 +273,7 @@ sub calculate {
     $i=1;
     while (my  @data = $dbcalc->fetchrow) {
         my ($row, $col )=@data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
         $i=1 if (($previous_col) and not($col eq $previous_col));
         $table[$i]->{$col}=$row;
 #		warn " $i $col $row";
diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl
index df9e4df..b379067 100755
--- a/reports/borrowers_stats.pl
+++ b/reports/borrowers_stats.pl
@@ -327,9 +327,9 @@ sub calculate {
 	my $emptycol; 
 	while (my ($row, $col, $value) = $dbcalc->fetchrow) {
 #		warn "filling table $row / $col / $value ";
-		$emptycol = 1 if ($col eq undef);
-		$col = "zzEMPTY" if ($col eq undef);
-		$row = "zzEMPTY" if ($row eq undef);
+		$emptycol = 1 if (!defined($col));
+		$col = "zzEMPTY" if (!defined($col));
+		$row = "zzEMPTY" if (!defined($row));
 		
 		$table{$row}->{$col}+=$value;
 		$table{$row}->{totalrow}+=$value;
diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl
index b5db4ed..c11c899 100755
--- a/reports/cat_issues_top.pl
+++ b/reports/cat_issues_top.pl
@@ -378,7 +378,7 @@ sub calculate {
     my %indice;
     while (my  @data = $dbcalc->fetchrow) {
         my ($row, $rank, $id, $col )=@data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
         $indice{$col}=1 if (not($indice{$col}));
         $table[$indice{$col}]->{$col}->{'name'}=$row;
         $table[$indice{$col}]->{$col}->{'count'}=$rank;
diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl
index 276294f..3addbe7 100755
--- a/reports/catalogue_stats.pl
+++ b/reports/catalogue_stats.pl
@@ -432,9 +432,9 @@ sub calculate {
 	my $emptycol; 
 	while (my ($row, $col, $value) = $dbcalc->fetchrow) {
 #		warn "filling table $row / $col / $value ";
-		$emptycol = 1    if ($col eq undef);
-		$col = "zzEMPTY" if ($col eq undef);
-		$row = "zzEMPTY" if ($row eq undef);
+		$emptycol = 1    if (!defined($col));
+		$col = "zzEMPTY" if (!defined($col));
+		$row = "zzEMPTY" if (!defined($row));
 		
 		$table{$row}->{$col}+=$value;
 		$table{$row}->{totalrow}+=$value;
diff --git a/reports/issues_avg_stats.pl b/reports/issues_avg_stats.pl
index 8d9d70d..1153aa3 100755
--- a/reports/issues_avg_stats.pl
+++ b/reports/issues_avg_stats.pl
@@ -543,9 +543,9 @@ sub calculate {
     while (my  @data = $dbcalc->fetchrow) {
         my ($row, $col, $issuedate, $returndate, $weight)=@data;
 #		warn "filling table $row / $col / $issuedate / $returndate /$weight";
-        $emptycol=1 if ($col eq undef);
-        $col = "zzEMPTY" if ($col eq undef);
-        $row = "zzEMPTY" if ($row eq undef);
+        $emptycol=1 if (!defined($col));
+        $col = "zzEMPTY" if (!defined($col));
+        $row = "zzEMPTY" if (!defined($row));
         # fill returndate to avoid an error with date calc (needed for all non returned issues)
         $returndate= join '-',Date::Calc::Today if $returndate eq '0000-00-00';
     #  DateCalc returns => 0:0:WK:DD:HH:MM:SS   the weeks, days, hours, minutes,
-- 
1.5.5.GIT




More information about the Koha-patches mailing list