2011-09-16 30 views
2

這是我的情況。從前面的問題中,我得到了從grep方法獲得價值的答案。如何確保空值不被輸入到mysql數據庫行?

while(<READFILE>) 
    { 
     my ($dbtest_name) = grep(/@/,@dataRecord); 

     // Next I insert this value into a mysql database I get the following error message. 

     $sth->execute($dbtest_name); 
    }  
     DBD::mysql::st execute failed: Column 'test' cannot be null 
     Use of uninitialized value $dbtest_name in print 

問題,我如何確保$ dbtest_name變量的值始終有一個值而不是null?

回答

6

使用defined功能:

next unless defined $dbtest_name;