Yes. I think you are right. I also get different results depending upon what has gone on before, but always the same results if the same things have previously happened. So, no matter how many times I run this:

c:\test>perl -wle"$#a = 10; print \$_ for @a" SCALAR(0x225138) SCALAR(0x225120) SCALAR(0x225144) SCALAR(0x225168) SCALAR(0x1824378) SCALAR(0x224f4c) SCALAR(0x2250f0) SCALAR(0x18243cc) SCALAR(0x18243d8) SCALAR(0x18243e4) SCALAR(0x18243f0)

I always get those same addresses. The thing I fond confusing is teh way the low and high areans get mixed up.

For example. When I run these two, notice how the first 7 addresses are the same in both, but then the last 3 vary.

c:\test>perl -wle"@b = 1.. 10; $#a = 10; print \$_ for @a" Name "main::b" used only once: possible typo at -e line 1. SCALAR(0x225138) SCALAR(0x225120) SCALAR(0x225144) SCALAR(0x225168) SCALAR(0x18243b0) SCALAR(0x1824428) SCALAR(0x1824434) SCALAR(0x1824440 +) SCALAR(0x182beac) SCALAR(0x182beb8) SCALAR(0x182bec4) c:\test>perl -wle"@b = 1.. 100; $#a = 10; print \$_ for @a" Name "main::b" used only once: possible typo at -e line 1. SCALAR(0x225138) SCALAR(0x225120) SCALAR(0x225144) SCALAR(0x225168) SCALAR(0x18243b0) SCALAR(0x1824428) SCALAR(0x1824434) SCALAR(0x1824440 +) SCALAR(0x182bd80) SCALAR(0x182bd8c) SCALAR(0x182bd98)

And if you go on to:

c:\test>perl -wle"@b = 1.. 1000; $#a = 10; print \$_ for @a" Name "main::b" used only once: possible typo at -e line 1. SCALAR(0x225138) SCALAR(0x225120) SCALAR(0x225144) SCALAR(0x225168) SCALAR(0x18243b0) SCALAR(0x1824428) SCALAR(0x1824434) SCALAR(0x1824440 +) SCALAR(0x2267c8) SCALAR(0x2267d4) SCALAR(0x2267e0)

It suddenly starts reusing earlier addresses.

It came up because I was trying to code something that would rely upon the relative address of the items in an array being in ascending order--but that's a guarentee that Perl simply cannot make.

What I really need access to is the (C) array of pointers pointed at by the ARRAY field of the XPVAV, but I would have to drop into XS to get that. Still that might be the only way to do what I am trying to do.

That said, inspiration hit me whilst typing this and I stuck the code is a begin block:

c:\test>perl -wle"BEGIN{ $#a = 10; print \$_ for @a }" SCALAR(0x182c120) SCALAR(0x182c114) SCALAR(0x182c12c) SCALAR(0x182c138 +) SCALAR(0x182c144) SCALAR(0x182c150) SCALAR(0x182c15c) SCALAR(0x182c168 +) SCALAR(0x182c174) SCALAR(0x182c180) SCALAR(0x182c18c)

And that seems to produce the effect I am after regardles of what else goes on, provided I ensure that my BEGIN block is run first. Or maybe I should just bite the bullet and code it in Inline::C.


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".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^2: Internals question. by BrowserUk
in thread Internals question. by BrowserUk

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.