Do you know where your variables are? | |
PerlMonks |
Re: Pass array, then clearby AnomalousMonk (Archbishop) |
on Jan 15, 2018 at 23:19 UTC ( [id://1207323]=note: print w/replies, xml ) | Need Help?? |
Is there a simple explanation for this? References be tricky, so I don't know how "simple" you will find this, but however...
In this first example, the anonymous reference address created in main and assigned to $data in that scope is passed to a separate variable in the scope of clear_it(), and that separate variable is assigned another anonymous reference address created therein. Notice how the the reference addresses change from point A to point B, yet are the same at points X, A and Y. After a new reference address is assigned to $data within clear_it(), whatever is done to the referenced contents (the referent) of $data inside of clear_it() can have no effect on the referent of the separate $data variable in main.
In this example, the reference address of an anonymous array in main is again passed to clear_it(), but this time an operation is performed by reference on the referent of the original reference, specifically, assigning it the empty list. Notice that the reference addresses at points X, A, B and Y are all the same. This seems like a perl idiosyncrasy. This is essentially the way references work in any language. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|