You can have your cake and eat it too :)

Use a prototype to avoid the backslash and assign the reference to a localised glob to avoid teh need to dereference in the sub.

#! perl -sw use strict; sub setmode ($\@) { ## the prototype makes the reference our @array; ## satisfy strict my $val = shift; local *array = shift; ## alias the reference splice @array, 1, 0, $val; ## do normal array operations } my @a = qw( one two three ); print join( "\n", @a ), "\n__________\n"; setmode 'add_test', @a; print join( "\n", @a ); __END__ [ 7:19:41.56] P:\test>junk3 one two three __________ one add_test two three

Whether the effort is worth may depend upon how much dereferencing you will do in the sub, and possibly whether the elements of the array might need further dereferencing.

Whether using prototypes, our and local is acceptable will depend upon your personal or corporate "acceptably unconfusing and mainatainable subset" of Perl's facilities and syntax.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re^2: Can @_ be extended? by BrowserUk
in thread Can @_ be extended? by hsmyers

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.