[Omaha.pm] not defined $bucket || $bucket eq '???'

Jay Hannah jhannah at omnihotels.com
Wed Dec 3 13:40:11 PST 2008


Oops. Hit a subtle bug in my code today because || considers '' true. 
 
Be careful out there...   :)
 
j
 
 

Index: Model/eWin/Transactions.pm
===================================================================
--- Model/eWin/Transactions.pm  (revision 3467)
+++ Model/eWin/Transactions.pm  (working copy)
@@ -108,7 +108,7 @@
       my $amount = $pms->{$tran_code};
       $sth->execute($property, $tran_code);
       my ($bucket) = $sth->fetchrow;
-      if (not defined $bucket || $bucket eq '???') {
+      if (not defined $bucket or $bucket eq '???') {
          $self->_complain_via_email($property, $tran_code, $crs);
          $bucket = '???';
       }
 
 
 
Bug demonstrated in the debugger.   :)
 
 
  DB<19> p $bucket
???

  DB<20> x (not defined $bucket || $bucket eq '???')
0  ''

  DB<21> x (not defined $bucket or $bucket eq '???')
0  1
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20081203/cef891ae/attachment.html>


More information about the Omaha-pm mailing list