What’s going on?

The explicit method populates the array with 7 physical pointers to undef:

[0] Perl> @x = (undef)x7;; [0] Perl> use Devel::Peek;; [No such file or directory] Perl> Dump \@x;; SV = RV(0x3c735d0) at 0x3c735c0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x3c6ac88 SV = PVAV(0x3cfafd8) at 0x3c6ac88 REFCNT = 2 FLAGS = (RMG) MAGIC = 0x3cee198 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x3c6a410 SV = PVMG(0x3b1a078) at 0x3c6a410 REFCNT = 1 FLAGS = (GMG,SMG,pIOK) IV = 6 NV = 0 PV = 0 MAGIC = 0x3ceea08 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x3c6ac88 ARRAY = 0x3cf1398 FILL = 6 MAX = 7 ARYLEN = 0x3c6a410 FLAGS = (REAL) Elt No. 0 SV = NULL(0x0) at 0x3cb4b98 REFCNT = 1 FLAGS = () Elt No. 1 SV = NULL(0x0) at 0x3c73578 REFCNT = 1 FLAGS = () Elt No. 2 SV = NULL(0x0) at 0x3cb49b8 REFCNT = 1 FLAGS = () Elt No. 3 SV = NULL(0x0) at 0x3cb4af0 REFCNT = 1 FLAGS = ()

Whereas, when you pre-extend the array, no physical pointer are populated; the undef's are implied by the absence of pointers:

[0] Perl> undef @x;; [0] Perl> $#x = 6;; [0] Perl> Dump \@x;; SV = RV(0x3c735d0) at 0x3c735c0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x3c6ac88 SV = PVAV(0x3cfafd8) at 0x3c6ac88 REFCNT = 2 FLAGS = (RMG) MAGIC = 0x3cee198 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x3c6a410 SV = PVMG(0x3b1a078) at 0x3c6a410 REFCNT = 1 FLAGS = (GMG,SMG,pIOK) IV = 6 NV = 0 PV = 0 MAGIC = 0x3ceea08 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x3c6ac88 ARRAY = 0x3cf1398 FILL = 6 MAX = 6 ARYLEN = 0x3c6a410 FLAGS = (REAL) Elt No. 0 Elt No. 1 Elt No. 2 Elt No. 3

Perl code would treat the two the as the same, but user-written XS code makes assumptions.

Thanks for checking it.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: What does my @x= (undef)x7; do? by BrowserUk
in thread What does my @x= (undef)x7; do? by gepebril69

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.