<?xml version="1.0" encoding="windows-1252"?>
<node id="1019935" title="Re: &quot;undef&quot; is not NULL and what to do about it" created="2013-02-21 06:14:45" updated="2013-02-21 06:14:45">
<type id="11">
note</type>
<author id="733061">
flexvault</author>
<data>
<field name="doctext">
&lt;p&gt;Good Day &lt;a href="http://www.perlmonks.org/?node_id=17000"&gt;Ovid&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;You stated:
&lt;hr&gt;&lt;ul&gt;&lt;i&gt;
So, between the ambiguity of Perl's "undef" and the clarity of SQL's NULL, it's probably not surprising that some code could use the latter instead of the former. In fact, I will go further as to assert that the code is often clearer if you do that. Case in point:&lt;/i&gt;
&lt;code&gt;
foreach my $employee (@employees) { 
   if ( $employee-&gt;salary &lt; $threshold ) { 
      increase_salary( $employee, 3_000 );
   } 
}
&lt;/code&gt;
&lt;i&gt;I'm sure plenty of you see the bug: what if the employee doesn't have a salary? I've already outlined several reasons above for why the salary might be undefined, not all of which mean "this employee has no salary..." 
&lt;/i&gt;&lt;/ul&gt;&lt;/p&gt;&lt;hr&gt;&lt;p&gt;
I'm confused by your example, and the code below shows why I'm confused. In memory the value for 'salary' is undefined, but once it written to disk, whenever it is accessed after the initial 'write', the field is defined. So if this is a quirk of the DB you're using, why expect Perl to fix it? Everyone else seems to understand you're problem, but it seems related to the DB you're using and not to a specific Perl problem.

&lt;code&gt;
    use strict;
    use warnings;

    my %Undef = ( Show =&gt; 'okay', Go =&gt; 'maybe', );

    foreach my $key ( keys %Undef )
    {    if ( ! defined $Undef{$key} ) { print "1. $key value is undefined!\n"; }
    }

    $Undef{Salary} = undef;

    foreach my $key ( keys %Undef )
    {    if ( ! defined $Undef{$key} ) { print "2. $key value is undefined!\n"; }
    }

    open ( my $file, "&gt;","./ondisk") || die " ! open |./ondisk| $!\n";
    foreach my $key ( keys %Undef )
    {    print $file "$key\t$Undef{$key}\n";         ## line 20
    }
    close $file;
    my %Defined; print "\n";
    open ( $file, "&lt;","./ondisk") || die " ! open |./ondisk| $!\n";
    while ( my $value = &lt;$file&gt; )
    {    chomp $value;
        my ( $newkey, $newvalue ) = split(/\t/,$value);
        $Defined{$newkey} = $newvalue;
    }
    close $file;

    foreach my $key ( keys %Defined )
    {    if ( defined $Defined{$key} ) { print "$key\t|$Defined{$key}|\n"; }
    }

1;
&lt;/code&gt;Results:
&lt;code&gt;
&gt; perl  unknown.plx

2. Salary value is undefined!
Use of uninitialized value $Undef{"Salary"} in concatenation (.) or string at unknown.plx line 20.

Go      |maybe|
Salary  ||
Show    |okay|


&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
Now if this is to solve a DB related flaw, then I see your point. But I don't understand how 'unknown' is better then 'undef/defined' in Perl scripts. YMMV!&lt;/p&gt;&lt;p&gt;
Maybe the title should have SQL in front of "NULL" to clarify the intent of the 'unknown'.

&lt;/p&gt;
&lt;p&gt;Regards...Ed&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-733061"&gt;
&lt;p&gt;&lt;b&gt;"Well done is better than well said." - Benjamin Franklin&lt;/b&gt;&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1019806</field>
<field name="parent_node">
1019806</field>
</data>
</node>
