in reply to Re^3: Two meanings of undef
in thread Two meanings of undef
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Two meanings of undef
by haukex (Archbishop) on Aug 16, 2020 at 09:10 UTC | |
|
Re^5: Two meanings of undef (updated)
by AnomalousMonk (Archbishop) on Aug 16, 2020 at 03:28 UTC | |
| |
|
Re^5: Two meanings of undef
by LanX (Saint) on Aug 16, 2020 at 10:57 UTC |