Received: from rly-ip01.mx.aol.com (rly-ip01.mx.aol.com [205.188.156.49]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA81471 for ; Thu, 18 May 2000 14:38:55 -0400 (EDT) (envelope-from mmayo@mcauleybrooklyn.org) Received: from tot-we.proxy.aol.com (tot-we.proxy.aol.com [205.188.195.1]) by rly-ip01.mx.aol.com (8.8.8/8.8.8/AOL-5.0.0) with ESMTP id OAA26525; Thu, 18 May 2000 14:37:07 -0400 (EDT) Received: from 362197428 (AC817F91.ipt.aol.com [172.129.127.145]) by tot-we.proxy.aol.com (8.10.0/8.10.0) with ESMTP id e4IIb5b04904; Thu, 18 May 2000 14:37:05 -0400 (EDT) Message-ID: <003c01bfc0f7$78e51f40$1138b798@362197428> From: "Michael A. Mayo" To: "Rudolph, Michael" , "'Alessio Bragadini'" Cc: References: Subject: Re: What is the difference between NULL and "undef" Date: Thu, 18 May 2000 14:32:47 -0400 Organization: Brooklyn College MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Apparently-From: PerlWebGuy@aol.com X-Archive-Number: 200005/62 ----- Original Message ----- From: "Rudolph, Michael" > But my original problem is not really solved > I read in a date from an input-field of an formular. I now have to > check, if this input-variable is empty. If it is, I set it to NULL, > if not, I take it as input. Unfortunately, there is no way to avoid testing for the empty string and assigning it to NULL or undef. It would be annoying if the empty string automatically translated to NULL, because it would be difficult to insert an empty string into a database. > My program looks now in parts like this: > if ($var3 == 0){ $var3 = NULL } # Testing if empty > else {$var3 = "'$var3'";} # input-field is not empty > $rc = $dbh->do("INSERT INTO test1 (var1,var2,var3) > VALUES ('$var1','$var2',$var3)"); You can also do this once for all the form variables instead of doing it separately for each: @fields = param(); foreach $current_field (@fields) { if( param($current_field) eq "" ) { param_fetch($current_field)->[0] = undef; } } This assumes you are using CGI.pm, but a similar method should be possible with the hash returned by ReadParse in cgi-lib or cgi_lite. As always, there's more than one way to do it. =) -Mike