Close, but no cigar:

use strict; use warnings; sub slice_ref { return \@_; } my @foo = (1..5); our @bar; *bar = slice_ref @foo[0..2]; print('foo: ', join(', ', @foo), "\n"); print('bar: ', join(', ', @bar), "\n"); print("\n"); $bar[0] = 'a'; print("After changing bar0:\n"); print('foo: ', join(', ', @foo), "\n"); print('bar: ', join(', ', @bar), "\n"); print("\n"); splice(@bar, 1, 0, 6); print("After inserting into bar:\n"); print('foo: ', join(', ', @foo), "\n"); print('bar: ', join(', ', @bar), "\n"); print("\n"); $bar[0] = 'b'; print("After changing bar0:\n"); print('foo: ', join(', ', @foo), "\n"); print('bar: ', join(', ', @bar), "\n"); __END__ output ====== foo: 1, 2, 3, 4, 5 bar: 1, 2, 3 After changing bar0: foo: a, 2, 3, 4, 5 bar: a, 2, 3 After inserting into bar: foo: a, 2, 3, 4, 5 Want: a, 6, 2, 3, 4, 5 bar: a, 6, 2, 3 After changing bar0: foo: b, 2, 3, 4, 5 The magic is still there bar: b, 6, 2, 3 on individual elements.

By the way, I think you asking for a solution that should not be used in a "heavily-used CPAN module".

Update: Fixed bug in slice_ref, and simplified it. Added comment at bottom.


In reply to Re: (Expert) Splicing a slice by ikegami
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.