Last active
August 29, 2015 14:05
-
-
Save sestaton/894c1b4a1b8bc9d7056f to your computer and use it in GitHub Desktop.
show the difference between defined and exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.010; | |
use strict; | |
use warnings; | |
my %hash = ( | |
id => undef, | |
id2 => 2, | |
); | |
if (!$hash{id}) { | |
say "'id' is not defined..."; | |
} | |
if (exists $hash{id}) { | |
say "but it exists in the hash!"; | |
} | |
if (exists $hash{id2} && defined $hash{id2}){ | |
say "'id2' exists and is defined."; | |
} | |
## running this prints: | |
# 'id' is not defined... | |
# but it exists in the hash! | |
# 'id2' exists and is defined. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment