--- "Collins, Joe (EDSI\\BDR)" <[EMAIL PROTECTED]> wrote: > Consider this perl stub: > > $value=$myhash{$mykey}; > > If the value in the hash at $mykey is "", then $value becomes "" and > if $mykey is not a valid key, then $value still becomes ""
Actually, that's not quite correct. If the $mykey exists in the hash and it is set to an empty string, then $value, in your first statement, will be set to an empty string. If $mykey does not exist in the hash, then trying to access it will "autovivify" that hash element (with no warnings, even if you have them on) and the value will be undef, not the empty string. To prevent this, you should generally check for the existence of a hash key before using a variable to access it: if ( exists $myhash{ $mykey } ) { $value = $myhash{ $mykey }; } else { warn "There is no key named '$mykey' in \%myhash."; } > How do I differentiate between the two? Use 'defined'. If the scalar contains an empty string, defined will return false. if ( defined $somevar ) { # $somevar might still be an empty string! } Cheers, Curtis "Ovid" Poe ===== Senior Programmer Onsite! Technology (http://www.onsitetech.com/) "Ovid" on http://www.perlmonks.org/ __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]