in reply to hash question

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: hash question
by duyet (Friar) on Jun 03, 2016 at 12:57 UTC
    Thanks! I guess i was confused between reference and alias.