in reply to What's a reference? What's a variable? What's scope?

That %sub_hash in your makehash function still "exists" (I said to myself, this is actually very VAGUE, what still exists? this can be interpreted in many ways, so...), or to be more precise, the memory allocated for it IS STILL ALLOCATED.

As long as THERE IS STILL REF TO that piece of memory, INITIALLY being allocated under the NAME of %sub_hash, Perl/Perl's garbage collecting will NOT deallocate that piece of memory.

Think about the "otherwise", otherwise you will have bunch of refs ref to memory spaces, which have been deallocated already. This breaks the PURPOSE of the programmer, in a normal case. Usually, the PURPOSE you return a ref, is that you still want to access whatever being ref'ed, why should Perl deallocate it? Perl is invented to SERVE your PURPOSE.
  • Comment on Re: What's a reference? What's a variable? What's scope?