Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: String equality and undef

by ccn (Vicar)
on Dec 09, 2008 at 12:18 UTC ( [id://729145]=note: print w/replies, xml ) Need Help??


in reply to String equality and undef

Test the value before use

perldoc -f defined

Replies are listed 'Best First'.
Re^2: String equality and undef
by Anonymous Monk on Dec 09, 2008 at 12:25 UTC
      if( $foo ){ ... }

      You cannot do this as the value returned may be 0 or the empty string both of which are not true:

      perl -e 'use DBI;$h = DBI->connect("dbi:ODBC:xxx","xxx","xxx");eval {$ +h->do("drop table mje")};$h->do("create table mje (a int null)");$s = + $h->prepare("insert into mje values(?)");$s->execute(0);$s->execute( +undef);$r = $h->selectall_arrayref("select * from mje");foreach (@$r) +{print "$_->[0]\n" if $_->[0];}'

      prints exactly nothing. You need to use defined. You may also find the following useful http://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_2.html#nulls.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://729145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found