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 to
undef $X;

In reply to Re^4: Two meanings of undef by likbez
in thread Two meanings of undef by likbez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.