I thought I'd read that perl does sparse arrays. So under what conditions does that happen? This simple test shows that @ary becomes a 1001 element array through this simple slice assignment. Perhaps related is that the uninitialized elements have the READONLY flag set which initialized yet undefined elements don't have. And then there's the super-wacky REFCNT value. I'd think that the READONLY flag is used by exists() and delete() but this code doesn't test that guess. Care to spread some enlightenment about sparse arrays and maybe the other part as well?

use Devel::Peek; @ary[1,100,500,1000] = (); DumpArray(@ary); __DATA__ .... Elt No. 998 0x4284 SV = NULL(0x0) at 0x4284 REFCNT = 2147483634 FLAGS = (READONLY) Elt No. 999 0x106d0 SV = NULL(0x0) at 0x106d0 REFCNT = 1 FLAGS = ()

In reply to Sparse arrays? by diotalevi

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.