Let's say I have the arrays
@foo = 1 .. 5; and
@bar = @foo[0..2]; I want to be able to
splice(@bar, 1, 0, 6); and have
is_deeply(\@foo, [1,6,2,3,4,5]); pass.
Basically, I want to have an array act as an alias to a sub-array of another array. If it helps, it can be a contiguous slice. I understand that slicing creates a completely new list, unrelated to the old one, so slicing as implemented isn't the answer.
I also know I can use tie for this, but I really want to avoid tie, if at all possible. The application1 of this is going into the refactoring of a heavily-used CPAN module, so performance is more important that a slight memory gain.
Is there a way to alias like I'm talking about? Or is this a Perl6-ism that isn't possible in Perl5? I would think that XS could provide a solution, but I don't know enough about XS to even make a stab at the feasibility of my crackpipe-dreams.
- Basically, I have an object which is a hashref that also contains an arrayref. I figured that I could make that into an arrayref as follows:
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.