Then again, depending on what you want to test for you may now also test whether it is undefined because it was assigned an undefined value (explicitly or implicitly) or because it was deleted (or never explicitly used in an assignment):

my @array; @array[3..9] = (3,4,undef,undef,7); delete @array[4,8]; print join"\n",map{defined $array[$_] ? "$_: $_" : exists $array[$_] ? "$_: undef-but-exists" : "$_: undef-not-exists"} 0 .. 10; __END__ OUTPUT: 0: undef-not-exists 1: undef-not-exists 2: undef-not-exists 3: 3 4: undef-not-exists 5: undef-but-exists 6: undef-but-exists 7: 7 8: undef-not-exists 9: undef-but-exists 10: undef-not-exists

This output may seem confusing. 0-3 don't exist because they were never assigned anything. 4 and 8 don't exist because we deleted them. 5 and 6 exist because we explicitly assigned the undef value to them. Element 9 does exist because when you assign a smaller list to a larger slice, the remainder of the slice is implictly assigned undef values. 10 doesn't exist because we've never assigned anything to it (we are beyond the end of the array).


In reply to Re: Re: On Removing Elements from Arrays by danger
in thread On Removing Elements from Arrays by footpad

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.