Perl commands - exists versus defined
http://stackoverflow.com/questions/6534573/whats-the-difference-between-exists-and-defined
http://perldoc.perl.org/functions/defined.html
http://perldoc.perl.org/functions/exists.html
if (defined $hash{$key}) { }
if (exists $hash{$key}) { }
defined checks to see if value for key is not undef. so key may exists but it was assigned undef.
exists checks to see if the key exists.
defined $hash{key} tells you whether or not the value for the given key is defined (i.e. not undef). Use it to distinguish between undefined values and values that are false in a boolean context such as 0 and ''.exists $hash{key} tells you whether or not %hash contains the given key. Use it to distinguish between undefined values and non-existent ones.
From JR's : articles
103 words - 754 chars
created on
updated on
import date 2013-08-12 21:50:52
- #
source
- versions