(There is no spoon, eh?)

Caveat: what I know of perlguts I mostly understand from reading PerlGuts Illustrated. From the "AV" section of that, the actual array storage data structure consists of pointers to the contents of each element of the array. That would suggest that you could use XS to get the pointers in two separate arrays to point to the same contents. I think that Data::Alias should be able to do that for you like this:

use Data::Alias; alias @x = @y; $x[1] = 2; # should make $y[1] == 2

If applied to a slice, that might get part of what you're looking for -- one array that is really just an alias a subsection of another array. The problem is that your example with splice won't work -- as splicing will just screw up the offsets, e.g. you'd get something like $x[2] pointing to $y[3]. You might be able to manually handle it, splicing and re-aliasing or something, but I'm not sure if the overhead of that leaves you with any performance gain.

Update: Data::Alias doesn't seem to be available for ActiveState. However, Lexical::Alias is and appears to be do the same kind of thing, albeit with different syntax, if that's an important consideration.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re: (Expert) Splicing a slice by xdg
in thread (Expert) Splicing a slice by dragonchild

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.