I was thinking of definedness in the defined sense, but after some testing I discovered something really bizarre:

Calling defined on an array that was declared as empty versus one that had been populated and then later emptied returns different results!

use strict; my @array = ( ); foreach ( ['initially empty', sub { }], [' undef as first', sub { @array = undef }], [' emptied', sub { @array = ( ) }], [' undefed', sub { undef @array }], [' emptied again', sub { @array = ( ) }], ) { my($name,$change) = @$_; $change->(); printf "%15s: %-5s %-9s\n", $name, ( @array ? 'true' : 'false' ), ( defined(@array) ? 'defined' : 'undefined' ); } __END__ initially empty: false undefined undef as first: true defined *********** emptied: false defined <-- ** HUH?! ** undefed: false undefined *********** emptied again: false undefined

I can reproduce the results under both 5.00503 and 5.6.1, but while I was ready to start screaming 'BUUUUUUUUGGG!', I then noticed 5.6.1 also spits out the following with warnings are enabled ...

defined(@array) is deprecated (Maybe you should just omit the defined()?)

Something to watch out for, I guess!

    --k.



In reply to Re: Re: Re: undef'ing @arrays caveat by Kanji
in thread undef'ing @arrays caveat by vladb

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.