@_ contaisn aliases to the parameters you pass, so if you work directly on $_[0], yo ucan change its value. It's the
my $t = shift;
that makes a copy.

There are several ways to make a variable alias to an existing value, but, shame on Perl, none are quite what I'd call "easy". For example:

*t = \($_[0]);
which uses a global variable $t. With local you can restrict the damage, but it'll still not pass strict — you still need to declare $t – but not using "my"!

another way is using for in a non-obious way (for can make a loop variable that is an alias for each item it iterates over, and with a scalar it will loop exactly one):

for my $t ($_[0]) { # ... the rest of the sub body }

There is even a few Alias modules on CPAN, the most interesting one always looked to me to be Data::Alias but I must confess I've never used it. (I tried to, long time ago, but it wouldn't compile back then.) Actually, looking at it now, I think Lexical::Alias might be more interesting — if it works.


In reply to Re: global, write-able vars by bart
in thread global, write-able vars by zeltus

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.