Re: NULL value question
- From: Klaus <klaus03@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 12:23:04 -0700
On Jul 31, 9:04 pm, Jim James <j...@xxxxxxxxxxxxx> wrote:
I'm coding my first web site using a mysql
database and DBI.
I can fetch records from the database
with no problem, but I'm having trouble
testing NULL values. If I load the value
of a date field into a variable ($dateadded),
how should the IF condition be written?
if ( $dateadded = NULL ) {
The single "=" is the assignment operator which does not test
anything, to test numerical equality use "==", to test stringwise
equality use "eq" (see perldoc perlop, equality operators).
I don't know anything about DBI, but I assume that NULL is a constant
string or number in DBI. Depending on whether it is a number or a
string, use '==' or 'eq'.
On the other hand, I would guess that DBI returns NULL values as
undefined scalars, in this case, neither "==", nor "eq" work as
expected. You should better use the defined function (see perldoc -f
defined)
if ( ! defined($dateadded) ) {
--
Klaus
.
- References:
- NULL value question
- From: Jim James
- NULL value question
- Prev by Date: Re: CGI displays contents of script
- Next by Date: Re: NULL value question
- Previous by thread: Re: NULL value question
- Next by thread: Re: NULL value question
- Index(es):
Relevant Pages
|