Perl-Sensitive Sunglasses | |
PerlMonks |
Re^4: Two meanings of undefby likbez (Sexton) |
on Aug 16, 2020 at 02:54 UTC ( [id://11120800]=note: print w/replies, xml ) | Need Help?? |
Thank you ! It is always a pleasure to see your replies. But it is a bad practice to use a key in hashes without quotes, as in $main::{X} ;-) A more revealing variant of your test would be [0] # cat undef_exists_test.pl use v5.10; say $main::{'X'}; say $X; say $main::{'X'}; if( exists $main::{'X'} ){ say "exists";} else {say "does not exist";} if( defined($X) ){say "defined";} else {say "not defined";} $X=1; undef $X; if( exists $main::{'X'} ){ say "exists";} else {say "does not exist";} if( defined($X) ){say "defined";} else {say "not defined";}Running it I got: *main::X *main::X exists not defined exists not defined [0] # We can see that even before the statement "say X;" executed the variable X was already added to the symbol table (during begin block execution?), So it does exists. NOTE: I think undef is not a value, as many here assume, but a function, So$X=undef;actually means in Perl:$X=undef();and is equivalent toundef $X;
In Section
Seekers of Perl Wisdom
|
|