Somewhat belatedly, it occurs to me to wonder if you have some confusion between the notions of reference and alias. Of course, an alias is just another name for a single thing. Neo is the alias in the Matrix of Thomas Anderson in the "real" world — whatever that is! Whatever happens to Neo in the Matrix happens to Anderson in the real world. *

Using aliasing, I can come up with a code example that behaves rather as you seem to expect the OPed code to behave. (Note that in Perl, the function argument list is always a list of aliases.)

c:\@Work\Perl>perl -wMstrict -MData::Dumper -le "my $hash = {}; print 'Ma: ', $hash; ;; do_something($hash); ;; print 'Mb: ', $hash; print Dumper($hash); ;; sub do_something { print 'Sa: ', $_[0]; ;; $_[0] = { a => 'alpha', b => 'beta', }; print 'Sb: ', $_[0]; print Dumper( $_[0] ); } " Ma: HASH(0x92d06c) Sa: HASH(0x92d06c) Sb: HASH(0x92d16c) $VAR1 = { 'a' => 'alpha', 'b' => 'beta' }; Mb: HASH(0x92d16c) $VAR1 = { 'a' => 'alpha', 'b' => 'beta' };
In this example, the value of the (aliased) reference changes as one would expect between points Sa and Sb in the subroutine, and also changes in exactly the same way between points Ma and Mb in the "real" world (as does the referent).

Update: * I think I got that wrong. Thomas Anderson is the alias in the Matrix for Neo, the real person extracted from his pod by Morpheus. Remember that Morpheus says to Neo "welcome to the desert of the real." (Jeeze, I gotta get a life...)


Give a man a fish:  <%-{-{-{-<


In reply to Re: hash question by AnomalousMonk
in thread hash question by duyet

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.